如何显示应用UI以接受和拒绝视频通话,并防止与其他正在进行的应用冲突?

问题描述 投票:1回答:1

我在Android应用程序中工作,用户接受或拒绝视频通话,这是正常的。但现在我想防止应用程序与其他人发生冲突,如果我们有任何其他调用,如应用程序或Skype。

然后我读了self managed connectionservice并尝试实现它。

Here is complete doc

从活动我首先注册

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(phoneAccountHandle,extras)上崩溃,后面跟着日志

/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) 
android android-6.0-marshmallow telecommunication
1个回答
0
投票

看起来您的AndroidManifest.xml中没有MANAGE_OWN_CALLS权限

© www.soinside.com 2019 - 2024. All rights reserved.