因为应用要使用手机的电话服务,所以要在清单文件AndroidManifest.xml中添加电话服务权限:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.itcast.action"
android:versionCode="1"
android:versionName="1.0">
略....
<uses-sdk android:minSdkVersion=“6" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
</manifest>
l
-----------------------------------------------------------------------------------------------------------------------------
public class MainActivity extends Activity
{
private EditText etPhone;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etPhone =
(EditText) findViewById(R.id.etPhone);
}
public void click(View
view)
{
String phone = etPhone.getText().toString().trim();
if(phone!=null &&
phone.length()>0)
{
//拨打电话
Intent intent = new Intent(Intent.ACTION_CALL,
Uri.parse("tel:"+
phone));
startActivity(intent);
}
else
{
Toast.makeText(this, "号码不能为空!",
1).show();
}
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。