当我单击callbutton时,我的程序停止了什么问题
public void callbutton(View v) { try{
intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:111*"+phone+"#"));
startActivity(intent);
}catch (ActivityNotFoundException e){
Toast.makeText(data.this, "noooo", Toast.LENGTH_SHORT).show();
}}
**我在清单中写了许可**
<uses-permission android:name="android.permission.CALL_PHONE" />
应该像这个
public void callbutton(View v) {
try {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:1234567890"));
startActivity(intent);
}catch (ActivityNotFoundException e){
Toast.makeText(Activity.this, "noooo", Toast.LENGTH_SHORT).show();
}
}
在API 23或更高版本上:您最使用此代码:
public void calling(String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(phoneNumber));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
or ::
public void callind(String phone) {
Intent callIntent = new Intent(Intent.ACTION_CALL); //use ACTION_CALL class
callIntent.setData(Uri.parse(phone)); //this is the phone number calling
//check permission
//If the device is running Android 6.0 (API level 23) and the app's targetSdkVersion is 23 or higher,
//the system asks the user to grant approval.
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
//request permission from user if the app hasn't got the required permission
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CALL_PHONE}, //request specific permission from user
10);
return;
}else { //have got permission
try{
startActivity(callIntent); //call activity and make phone call
}
catch (android.content.ActivityNotFoundException ex){
Toast.makeText(getApplicationContext(), "did not work", Toast.LENGTH_SHORT).show();
}
}
}
在API 23及更少:您可以使用此代码:
public void callind(String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(phoneNumber));
startActivity(intent);
}
}
在拖曳方面,您必须添加清单权限:
<uses-permission android:name="android.permission.CALL_PHONE" />