【发布时间】:2019-01-13 14:08:35
【问题描述】:
我在运行 Android API 27 的物理设备 (Samsung 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 邀请项目并得到相同的行为:
- 适用于运行 API21 的物理设备。
- 在运行 API28 的物理设备上失败
我仍然认为这一定是我想念的东西,因为即使是最简单的测试也失败了,这不太可能。
【问题讨论】:
标签: android firebase android-notifications firebase-invites