我在运行Android API 27的物理设备(三星SM-J710F)上收到此错误。相同的代码在运行API 21的物理设备上也能很好地工作。
我使用Firebase文档中的以下Kotlin代码进行测试:
private fun onClick() {
val intent = AppInviteInvitation.IntentBuilder("Title test")
.setMessage("Invite Test")
.setCallToActionText("call back test")
.build()
startActivityForResult(intent, REQUEST_INVITE)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
Log.d(TAG, "onActivityResult: requestCode=$requestCode, resultCode=$resultCode")
if (requestCode == REQUEST_INVITE) {
if (resultCode == Activity.RESULT_OK) {
// Get the invitation IDs of all sent messages
val ids = AppInviteInvitation.getInvitationIds(resultCode, data!!)
for (id in ids) {
Log.d(TAG, "onActivityResult: sent invitation $id")
}
} else {
//resultCode is always Activity.RESULT_CANCELED (0)
}
}
}
等级:
implementation 'com.google.firebase:firebase-invites:16.0.6'
电子邮件已发送,但活动结果返回:
resultCode
始终是Activity.RESULT_CANCELED(0)我在类似的帖子中发现了这个answer,说这个特定的错误可能在Android 8设备上发生。
这是完整的堆栈:
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@ea2626
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_54380(LoadedApk.java:1365)
at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.$m$7(Unknown Source:4)
at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.run(Unknown Source:39)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@abaa43e -- permission denied for window type 2003
at android.view.ViewRootImpl.setView(ViewRootImpl.java:1026)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:384)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:101)
at gkf.a(:com.google.android.gms@14799017@14.7.99 (040306-223214910):23)
at gkf.a(:com.google.android.gms@14799017@14.7.99 (040306-223214910):15)
at gkf.a(:com.google.android.gms@14799017@14.7.99 (040306-223214910):1)
at com.google.android.gms.appinvite.AppInviteChimeraActivity.a(:com.google.android.gms@14799017@14.7.99 (040306-223214910):107)
at com.google.android.gms.appinvite.AppInviteChimeraActivity$AppInviteResponseReceiver.a(:com.google.android.gms@14799017@14.7.99 (040306-223214910):2)
at ygn.onReceive(:com.google.android.gms@14799017@14.7.99 (040306-223214910):1)
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_54380(LoadedApk.java:1355)
at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.$m$7(Unknown Source:4)
at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.run(Unknown Source:39)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
看看堆栈,它发现原来的问题是权限:
Unable to add window android.view.ViewRootImpl$W@abaa43e -- permission denied for window type 2003
通过同样的answer,需要更改Firebase请求权限的方式,而我不能这样做。我被困在这里。
更新: 我尝试使用Firebase quickstart邀请项目,并得到相同的行为:
我仍然认为这一定是我想念的东西,因为即使最简单的测试也无法通过,这似乎不太合理。