在我的应用程序中,我需要在某些情况下以编程方式发起呼叫。
它大部分时间都有效,但我可以看到有时它不起作用,特别是在 2.3.7 版本上。也许该特定权限已删除并且在该版本中是非法的?我找不到有关异常起源的线索。
我在清单中获得了许可:
<uses-permission android:name="android.permission.CALL_PHONE" />
的java代码:
private void launchCall(String number, int calltype) {
Intent callIntent = new Intent();
callIntent.setAction(Intent.ACTION_CALL);
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.setData(Uri.parse("tel:"+ number));
if (calltype == CALL_TYPE_VIDEO) {
callIntent.setAction(ACTION_VIDEO_CALL);
callIntent.putExtra("videocall", true);
}
context.startActivity(callIntent);
}
异常跟踪:
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxx-xxx-xxxx flg=0x10000000 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{415f7158 4016:com.tawkon/10092} (pid=4016, uid=10092) requires android.permission.CALL_PHONE
at android.os.Parcel.readException(Parcel.java:1322)
at android.os.Parcel.readException(Parcel.java:1276)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1359)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
at android.app.ContextImpl.startActivity(ContextImpl.java:640)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
at com.tawkon.Service.PrecallSuggestionManager.launchCall(PrecallSuggestionManager.java:305)
at com.tawkon.Service.PrecallSuggestionManager.access$12(PrecallSuggestionManager.java:291)
at com.tawkon.Service.PrecallSuggestionManager$6.run(PrecallSuggestionManager.java:215)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3703)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)