1

I spent a few hours researching this with no luck, so I'm asking here. I've already checked these questions to no avail:

Up until today (AFAIK — I haven't tested it in a while), Firebase Cloud Messaging was working just fine. I could send a notification with data from the Firebase Console, and using getIntent().getExtras() would allow me to access that data from the app.

Today, however, I sent a test notification, but tapping it did not perform the expected action. After some digging, I found out that getIntent().getExtras() was just returning null no matter what. This is the relevant code:

private void respondToNotificationClick() {
    if (getIntent().getExtras() != null) {
        Log.e("NOTIF", "NOTIF");
        //...
    }
}

(This method is called from both onCreate() and onResume() in the main activity.)

But that log is never printed, and if I try to log Intent.getExtras() outside of the if statement, I get an NPE.

I suspect it has something to do with Firebase 11 vs 10 or maybe that this app is targeting API 26, but I just can't figure out how to fix it, and Google's documentation isn't always the most helpful.

What's going on here? Is it a known issue? Is it because I'm using a beta API (even though it's supposed to have been finalized)?

KENdi
  • 7,670
  • 2
  • 15
  • 27
TheWanderer
  • 15,461
  • 6
  • 46
  • 60
  • FWIW--Works for me using 11.0.1 on an API 24 device – Bob Snyder Jun 25 '17 at 20:23
  • @BobSnyder is it possible that I'm being a complete derp and I need Google Play Services? – TheWanderer Jun 25 '17 at 20:28
  • 1
    Yes, I was just thinking about that. Definitely needed. If you are using an emulator, there is not yet a released image that contains GPS for API 26. Updated for lower APIs were just released a few days ago. – Bob Snyder Jun 25 '17 at 20:34
  • @BobSnyder I'm a smart one.... I'll test out GPS when I can, but this question can probably be closed. – TheWanderer Jun 25 '17 at 20:35
  • [GoogleApiAvailability](https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability) is a handy collection of features to check for GPS. – Bob Snyder Jun 25 '17 at 20:39
  • I am a little confused though. Why is the emulator able to receive Firebase notifications? Is it just the data handling that GPS is needed for? – TheWanderer Jun 25 '17 at 20:40
  • Hmm. So I just tried on my API 25 device and it doesn't log that "NOTIF" string, either. – TheWanderer Jun 25 '17 at 20:51

1 Answers1

5

Not an answer, but I have too much to share for comments...

It sounds like you are running on an API 26 emulator. As I noted in a previous comment, an API 26 emulator image has not yet been released that is compatible with Firebase 11.0.1. When I run on an API 26 emulator, the version incompatiblity is confirmed by this log message:

W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11011000 but found 10930470

Despite that, a notification sent from the Firebase console (with no data values) appears, and when touched invokes my launcher activity. In the onCreate() method of that activity I have this code:

    Intent intent = getIntent();
    if (intent != null) {
        Bundle b = intent.getExtras();
        if (b != null) {
            Set<String> keys = b.keySet();
            for (String key : keys) {
                Log.d(TAG, "Bundle Contains: key=" + key);
            }
        } else {
            Log.w(TAG, "onCreate: BUNDLE is null");
        }
    } else {
        Log.w(TAG, "onCreate: INTENT is null");
    }

which produces this output:

 D/MainActivity: Bundle Contains: key=google.sent_time
 D/MainActivity: Bundle Contains: key=from
 D/MainActivity: Bundle Contains: key=google.message_id
 D/MainActivity: Bundle Contains: key=collapse_key

So my previous comments about Google Play services being the problem were mistaken. The behavior you are observing is caused by something else.

Bob Snyder
  • 36,508
  • 5
  • 108
  • 154
  • 1
    Hmm. It also fails on a physical API 25 tablet. I guess I'll just have to wait. This is enough of an answer for me. – TheWanderer Jun 25 '17 at 21:40