1

To despite the error in my code i downloaded and run the Invite project from Firebase quickstart-android and run it on 2 physical androids.

When running on API 21 i get the IDs of the sent invites.

When running on API 27 the Invite activity returns code CANCELED and null for Intent, but the emails are send successfully.

I review the documentation and can't find anything that i didn't do. I try to request user permission to access Contacts at runtime but no luck.

Here the code from the sample:

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();

    intent.putExtra(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));

    startActivityForResult(intent, REQUEST_INVITE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode);

    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 {
            //always return CANCELED (0), even the email are send sucessufly
            showMessage(getString(R.string.send_failed));

        }
    }
}

I got this error on the log:

 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)

The first exception throw says permission denied for window type 2003. From other posts seems it seams that the Invite Activity is trying to launch some window that requires SYSTEM_ALERT_WINDOW permission and that is not permitted after Android 6.

I am stuck here. The Firebase library is currently up to date (version 16.0.6).

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169
  • Just a guess cause it is late and can't sleep : ) https://developer.android.com/guide/components/broadcasts I think there was a change in broadcasts for Android 8...had Problems with that too, but dont remeber exactly what I changed...but was about braodcast receiver – user1804084 Jan 17 '19 at 00:41
  • I don't see nothing that i can use. The only option would be something to add to manifest, all things seem to be made inside the activity. Anyway, the solution should be fix the access error or prevent what ever is causing the activity to try to open that window. – MiguelSlv Jan 17 '19 at 09:36

0 Answers0