有没有办法在没有显示允许用户发起呼叫的UI的情况下呼叫联系人?因此,当我点击一个按钮时,会立即拨打联系电话号码,就像我在手机中拨打最后一个电话时点击某人一样,会立即拨打电话。
我现在使用的代码是:
try {
Intent intent = new Intent(Intent.CALL_ACTION);
intent.setData(Uri.parse("tel:" + number));
startActivity(intent);
} catch (Exception e) {
Log.e("SampleApp", "Failed to invoke call", e);
}
答案 0 :(得分:4)
向清单添加权限android.permission.CALL_PHONE
,并将Intent.CALL_ACTION
更改为Intent.ACTION_CALL
答案 1 :(得分:2)
您发布的代码不应该有效... 没有CALL_ACTION,请改用ACTION_CALL。
答案 2 :(得分:1)
private void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
} catch (ActivityNotFoundException e) {
Log.e("helloandroid dialing example", "Call failed", e);
}
的的AndroidManifest.xml 强> 的
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
答案 3 :(得分:0)
Intent intent = new Intent(Intent.CALL_ACTION);
应该是
Intent intent = new Intent(Intent.ACTION_CALL);
这是我的完整代码:
Intent intentcall = new Intent();
intentcall.setAction(Intent.ACTION_CALL);
intentcall.setData(Uri.parse("tel:" + phoneNumber));
startActivity(intentcall);