如何使Firebase邀请在模拟器上工作? [英] How to make Firebase Invites work on emulator?

查看:63
本文介绍了如何使Firebase邀请在模拟器上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在根据官方网站上的教程在模拟器中测试 Firebase邀请.

I am testing Firebase Invites from an emulator based on tutorial from official site.

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

使用的仿真器:

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

CPU/ABI: Google Play Intel Atom (x86)

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

Target: google_apis_playstore [Google Play] (API level 28)

皮肤:pixel_2

Skin: pixel_2

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

I try to call activity for result like this.

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作为结果代码.

But in activityOnResult I always get Activity.RESULT_CANCELLED as a result code.

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
        // ...
    }
}

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

It turns out that it is because there is a crash in invites library:

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) 

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

This happens only on emulator and not on physical device.

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

Anyone knows how to make Firebase Invites work also on emulator?

推荐答案

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

WindowManager.LayoutParams constant 2003 is TYPE_SYSTEM_ALERT, deprecated in API level 26. either build against API 25 (which may be that physical device) or use TYPE_APPLICATION_OVERLAY instead. with a single line from the build.gradle it's difficult to understand against which API the code even runs.

提示:请确保在安装了Play服务的仿真器映像上运行此程序.

hint: make sure you run this on an emulator image with Play Services installed.

这篇关于如何使Firebase邀请在模拟器上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆