如何使Firebase邀请在模拟器上工作?

时间:2018-10-06 10:41:26

标签: android firebase firebase-invites

我正在根据官方网站上的教程在仿真器上测试Firebase Invites

implementation 'com.google.firebase:firebase-invites:16.0.4'

使用的仿真器:

  

CPU / ABI:Google Play英特尔凌动(x86)

     

目标:google_apis_playstore [Google Play](API级别28)

     

皮肤:pixel_2

我试图称这样的结果为活动。

private void onInviteClicked() {
    Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
            .setMessage(getString(R.string.invitation_message))
            .setDeepLink(Uri.parse(getString(R.string.invitation_deep_link)))
            .setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
            .setCallToActionText(getString(R.string.invitation_cta))
            .build();
    startActivityForResult(intent, REQUEST_INVITE);
}

但是在activityOnResult中,我总是得到Activity.RESULT_CANCELLED作为结果代码。

if (requestCode == REQUEST_INVITE) {
    if (resultCode == RESULT_OK) {
        // Get the invitation IDs of all sent messages
        String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
        for (String id : ids) {
            Log.d(TAG, "onActivityResult: sent invitation " + id);
        }
    } else {
        // Sending failed or it was canceled, show failure message to the user
        // ...
    }
}

事实证明,这是因为邀请函库发生崩溃:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.android.gms.ui, PID: 10555
java.lang.RuntimeException: Error receiving broadcast Intent { act=com.google.android.gms.appinvite.intent.action.INVITE_SENT cat=[android.intent.category.DEFAULT] flg=0x10 (has extras) } in com.google.android.gms.appinvite.AppInviteChimeraActivity$AppInviteResponseReceiver@d32d00e
    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1401)
    at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@93c43be -- permission denied for window type 2003
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:822)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
    at fzg.a(:com.google.android.gms@14366040@14.3.66 (100700-213742215):22)
    at fzg.a(:com.google.android.gms@14366040@14.3.66 (100700-213742215):15)
    at fzg.a(:com.google.android.gms@14366040@14.3.66 (100700-213742215):1)
    at com.google.android.gms.appinvite.AppInviteChimeraActivity.a(:com.google.android.gms@14366040@14.3.66 (100700-213742215):91)
    at com.google.android.gms.appinvite.AppInviteChimeraActivity$AppInviteResponseReceiver.a(:com.google.android.gms@14366040@14.3.66 (100700-213742215):2)
    at xbc.onReceive(:com.google.android.gms@14366040@14.3.66 (100700-213742215):1)
    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0(LoadedApk.java:1391)
    at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2) 
    at android.os.Handler.handleCallback(Handler.java:873) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:193) 
    at android.app.ActivityThread.main(ActivityThread.java:6669) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

这只会在模拟器上发生,而不会在物理设备上发生。

任何人都知道如何使Firebase邀请在模拟器上也能工作吗?

1 个答案:

答案 0 :(得分:2)

WindowManager.LayoutParams常量2003TYPE_SYSTEM_ALERT,在API级别26中已弃用。可以根据API 25(可能是该物理设备)构建,也可以使用TYPE_APPLICATION_OVERLAYbuild.gradle中只有一行,很难理解代码甚至针对哪个API运行。

提示:请确保在安装了Play服务的模拟器映像上运行此提示。