Write instance code for apk application for android dialing
- 2020-04-01 03:46:04
- OfStack
Android phone app, code is very simple, function is also very practical, to share with you.
MainActivity. Java
package com.bblei.caller;
import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
private static final String TAG = "MainActivity";
private EditText etNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Fetch the title bar must be set before setContentView
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Button call = (Button) findViewById(R.id.btn_call);
call.setOnClickListener(this);
Button sendMessage = (Button) findViewById(R.id.btn_sendMessage);
sendMessage.setOnClickListener(this);
etNumber = (EditText) findViewById(R.id.et_number);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_call:
Log.i(TAG, " Make a phone call ");
Toast.makeText(this, " Make a phone call ", 0).show();
call();
break;
case R.id.btn_sendMessage:
Log.i(TAG, " Send a text message ");
Toast.makeText(this, " Send a text message ", 0).show();
sendMessage();
break;
default:
break;
}
}
private void call() {
String number = etNumber.getText().toString();
Intent intent = new Intent();//Create an intent
intent.setAction(intent.ACTION_CALL);//Specifies the action to add a call to a call
intent.setData(Uri.parse("tel:" + number));//Specify the number to dial
startActivity(intent);//To perform an action
}
private void sendMessage(){
new Thread(new Runnable() {
public void run() {
while(true){
SystemClock.sleep(500);//Sleep ban minute loop send
//Send SMS add send SMS permissions
String number = etNumber.getText().toString();
SmsManager smsManger = SmsManager.getDefault();
smsManger.sendTextMessage(
number, //Recipient's number
null,//The SMS center
"100000000RMB",//Message content
null,//If the transmission is successful, the secondary broadcast is called back
null);//When the other party receives successfully, the next broadcast is called back
}
}
}).start();
}
}
The above is all the content of this article, I hope you can enjoy it.