如何在android中拨打电话
我正试图从我的应用程序中点击一个图像进行调用 它是这样做的,但它给了我异常活动NotFoundException 我该如何处理这件事如何在android中拨打电话,android,call,Android,Call,我正试图从我的应用程序中点击一个图像进行调用 它是这样做的,但它给了我异常活动NotFoundException 我该如何处理这件事 Image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if("N/A".equals(Num
Image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if("N/A".equals(Number)){
MsgBox(ctx,"Could not call because there is no number ");
}
else{
fnCallMobile("+91"+Number);
}
}
});
我的手机功能是:
public void fnCallMobile(String PhoneNo){
ConfirmMsgBox(this,"Are you sure you want to call number "+PhoneNo,PhoneNo);
}
public void ConfirmMsgBox(Context ctx,String msg,final String sPhoneNo){
final AlertDialog.Builder dialog=new AlertDialog.Builder(this);
dialog.setTitle("Emkay Eagle");
dialog.setMessage(msg);
dialog.setCancelable(false);
dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
fnCall(sPhoneNo);
}
});
dialog.setNegativeButton("No", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
return;
}
});
AlertDialog alert = dialog.create();
alert.setIcon(R.drawable.icon);
alert.show();
return;
}
最后是我的fnCall函数
public void fnCall(String PhoneNo){
try{
Intent callIntent=new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("Tel:"+PhoneNo));
startActivity(callIntent);
}
catch(ActivityNotFoundException ex){
sResponse=ex.toString();
}
}
将方案用作电话:而不是电话:
callIntent.setData(Uri.parse("tel:"+PhoneNo));
它适合我。在URI中,您应该使用
tel:
而不是。tel:
,因为协议区分大小写。请注意,这是由您的错误所提示的,它告诉您您的URI是错误的。问题出在哪里?如果您的URI中有错误,那么您的代码似乎很好manifest@Akki它让我在尝试将协议更改为“tel”
(小写)时,在意图附近出现Activity Not Found Exception。不确定,但可能区分大小写。我已经声明了许可,当它涉及到意图时,它会提供异常活动NotFoundException?Tel和Tel之间的区别是什么?虽然Thnaks先生的工作开始得很好,但Tel和Tel之间的区别是什么?Java是区分大小写的语言。谢谢Chirag,你做得很好
String uri = "tel:" + number;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);
String uri = "tel:" + number;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);