我在一个android应用程序中工作,其中用户接受或拒绝视频呼叫,这是工作正常。但现在我想防止应用程序与其他人的冲突,如果我们有任何其他呼叫,如什么是应用程序或skype。
然后,我已经阅读了self managed connectionservice并尝试实现它。
从活动I首先注册
TelecomManager tm = (TelecomManager)
getSystemService(Context.TELECOM_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
{
PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(
new ComponentName(this.getApplicationContext(), MyConService.class),
"example");
PhoneAccount phoneAccount = PhoneAccount.builder(phoneAccountHandle, "example")
.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED).build();
tm.registerPhoneAccount(phoneAccount);
}然后尝试添加新的调用,如下所示:
PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(
new ComponentName(this.getApplicationContext(), MyConService.class),
"example");
Bundle extras = new Bundle();
Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, "11223344", null);
extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri);
tm.addNewIncomingCall(phoneAccountHandle, extras);应用程序总是在tm.addNewIncomingCall上崩溃,日志如下
/AndroidRuntime: FATAL EXCEPTION: main Process: com.liverep.videochat, PID: 27754
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.liverep.videochat/com.liverep.videochat.VideoChat}: java.lang.SecurityException: This PhoneAccountHandle is not enabled for this user!
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.SecurityException: This PhoneAccountHandle is not enabled for this user!
at android.os.Parcel.readException(Parcel.java:1693)
at android.os.Parcel.readException(Parcel.java:1646)
at com.android.internal.telecom.ITelecomService$Stub$Proxy.addNewIncomingCall(ITelecomService.java:1450)
at android.telecom.TelecomManager.addNewIncomingCall(TelecomManager.java:1225)
at com.liverep.videochat.VideoChat.placeIncomingCall(VideoChat.java:792)
at com.liverep.videochat.VideoChat.call(VideoChat.java:730)
at com.liverep.videochat.VideoChat.registerForPhoneCall(VideoChat.java:716)
at com.liverep.videochat.VideoChat.onCreate(VideoChat.java:133)
at android.app.Activity.performCreate(Activity.java:6942)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 发布于 2018-06-18 16:28:31
看起来您在AndroidManifest.xml中没有MANAGE_OWN_CALLS权限
发布于 2019-10-03 22:46:43
正确注册您的PhoneAccount,然后使用addNewIncomingCall()。在我的例子中,它起作用了。
telecomManager.registerPhoneAccount(phoneAccount1);
telecomManager.addNewIncomingCall(myPhoneAccountHandle,bundle);https://stackoverflow.com/questions/47916611
复制相似问题