Android app for making phone calls. The code is very simple and the functions are very practical. I would like to share it 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.telphony.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); // To remove the title bar, requestWindowFeature(Window.FEATURE_NO_TITLE) must be set before setContentView; 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, "Call"); Toast.makeText(this, "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); // Specify its action to make a call and add a call action intent.setData(Uri .parse("tel:" + number));//Specify the number to dial startActivity(intent);//Execute the action} private void sendMessage(){ new Thread(new Runnable() { public void run() { while(true){ SystemClock.sleep(500); //Sleep ban minute cycle sending //Send text messages to add permission to send text messages String number = etNumber.getText().toString(); SmsManager smsManger = SmsManager.getDefault(); smsManger.sendTextMessage( number, //The recipient's number is null, //SMS center "100000000RMB", //SMS content is null, //If sent successfully, callback broadcast null); //When the other party receives successfully, callback broadcast} } }). start(); }}
The above is the entire content of this article, I hope you all like it.