打电话打短信的实现
加权限:
首先要分别添加权限,权限如下同时可以API 里找到相关权限,在android 下面 Manifest。Permission
<uses-permission android:name="android.permission.CALL_PHONE"/> 打电话
<uses-permission android:name="android.permission.SEND_SMS" />发短息
关于XML的声明空间跳过
实现打电话的主要代码如下:
public class Call extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.dail);
final EditText edit = (EditText) findViewById(R.id.edit);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(Call.this, "拨号成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
+ edit.getText().toString()));
Call.this.startActivity(intent);
}
});
}
发送短信的主要代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
no = (EditText) findViewById(R.id.no);
sms = (EditText) findViewById(R.id.sms);
send = (Button) findViewById(R.id.send);
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String tel = no.getText().toString();
String content = sms.getText().toString();
//得到一个短息管理器
SmsManager manger = SmsManager.getDefault();
//自动拆分短信!
ArrayList<String> str = manger.divideMessage(content);
for (String s : str) {
manger.sendTextMessage(tel, null, s, null, null);
Toast.makeText(MSMDemo.this, "单击了发送", Toast.LENGTH_SHORT)
.show();
}
}
});
}
如有错!请谅解
加权限:
首先要分别添加权限,权限如下同时可以API 里找到相关权限,在android 下面 Manifest。Permission
<uses-permission android:name="android.permission.CALL_PHONE"/> 打电话
<uses-permission android:name="android.permission.SEND_SMS" />发短息
关于XML的声明空间跳过
实现打电话的主要代码如下:
public class Call extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.dail);
final EditText edit = (EditText) findViewById(R.id.edit);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(Call.this, "拨号成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
+ edit.getText().toString()));
Call.this.startActivity(intent);
}
});
}
发送短信的主要代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
no = (EditText) findViewById(R.id.no);
sms = (EditText) findViewById(R.id.sms);
send = (Button) findViewById(R.id.send);
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String tel = no.getText().toString();
String content = sms.getText().toString();
//得到一个短息管理器
SmsManager manger = SmsManager.getDefault();
//自动拆分短信!
ArrayList<String> str = manger.divideMessage(content);
for (String s : str) {
manger.sendTextMessage(tel, null, s, null, null);
Toast.makeText(MSMDemo.this, "单击了发送", Toast.LENGTH_SHORT)
.show();
}
}
});
}
如有错!请谅解