Android studio android studio m中的Broblem in ACTION_调用代码
当我单击callbutton时,我的程序停止了问题出在哪里Android studio android studio m中的Broblem in ACTION_调用代码,android-studio,Android Studio,当我单击callbutton时,我的程序停止了问题出在哪里 public void callbutton(View v) { try{ intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:111*"+phone+"#")); startActivity(intent); }catch (ActivityNotFoundException e){
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);
}
}
或:
在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" />
我找到了问题的答案,谢谢大家。
<uses-permission android:name="android.permission.CALL_PHONE" />