phone, text message

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener ;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.EditText;


public class MainActivity extends Activity implements OnClickListener, OnLongClickListener {
//Views in the layout must declare member variables
EditText edt1,edt2;
Button btn1,btn2;
//The onCreate method will be called when the program starts
@Override
protected void onCreate(Bundle savedInstanceState) {
//Call the oncreate method of the parent class to perform some initialization operations
super.onCreate(savedInstanceState);
//Load the layout and generate the corresponding attempt object
setContentView(R.layout.activity_main);
info();
}
private void info() {
//Get the object
edt1 = (EditText) findViewById(R. id.editText1);
edt2 = (EditText) findViewById(R.id.editText2);
btn1 = (Button) findViewById(R.id.button1);
btn2 = (Button) findViewById(R.id.button2);
//short Press listener
edt1.setOnClickListener(this);
edt2.setOnClickListener(this);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
//Long press listener
btn1.setOnLongClickListener(this);
btn2.setOnLongClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
//Create an intent implicit
String in = Intent.ACTION_DIAL;
Intent intent =new Intent(in);
//carry Data
String nnn=edt1.getText().toString().trim();
//intent.putExtra("GB", nnn);
intent.setData(Uri.parse("tel:"+nnn)) ;
//intent.putExtra("GB ", nnn); Start
startActivity(intent);
break;
case R.id.button2:
//Create an intent implicit
Intent inv = new Intent(Intent.ACTION_SENDTO);
//carry data
String nc=edt1.getText().toString(). trim();
String sms=edt2.getText().toString().trim();
inv.setData(Uri.parse("smsto:"+nc));
inv.putExtra("sms_body", sms);
//Start
startActivity(inv);
break;
}
}
//Long press monitor
@Override
public boolean onLongClick(View v) {
switch (v.getId()) {
case R.id.button1:
//Create an intent hermit
String ca = Intent.ACTION_DIAL;
Intent intent =new Intent(ca);
//carry data
String in = edt1.getText().toString().trim();
intent.setData(Uri.parse("til:"+in ));
//Start
startActivity(intent);
break;
case R.id.button2:
//Get the SmsManager object
SmsManager sm = SmsManager.getDefault();
//Send text information
String smn = edt1.getText().toString( ).trim();
String smc = edt2.getText().toString().trim();
sm.sendTextMessage(smn, null, smc, null,null);
break;
}
return true;//Indicates that the event has been fired and will not be clicked again event
}

}




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325797191&siteId=291194637