Android push.on('registration', cb) fires correctly on device, but not in emulator. #204

Closed
alexklibisz opened this Issue Oct 5, 2015 · 6 comments

Projects

None yet

2 participants

@alexklibisz

Is there any reason that this plugin would not work in an Android emulator but work on an actual device (using the same APK file)?

I'm using Cordova/Ionic to build an angular-based app. I began using the push plugin suggested by the ngCordova project: ttps://github.com/phonegap-build/PushPlugin.git, but I had problems with it, and it's deprecated, so I've switched to this one.

When I run my app on an Android Emulator (the default Android Emulator, on Linux), the push.on('registration') callback does not fire at all. When I build and run on my device (HTC One), it fires correctly. Here is my rather straightforward registration code, which is run after 'deviceready' event:

var push = PushNotification.init({
        "android": {
          "senderID": "111222333444555666"
        },
        "ios": {
          "alert": "true",
          "badge": "true",
          "sound": "true"
        },
        "windows": {}
      });

      push.on('registration', function(data) {
        console.log(data);
      });

I have the following Android packages installed:

Android SDK Tools, 24.4
Android SDK Build-tools, 23.0.1
Android SDK Build-tools, 23,
Android SDK Platform-tools, 23.1 rc1
Android 6.0 (API 23)
...SDK Platform
...Intel x86 atom system image
...Sources for Android SDK
Android 5.1.1 (API 22)
...SDK Platform
...Intel x86 atom system image
Extras
...Android SUpport Repository, 21
...Android Support Library, 23.0.1
...Google Repository, 22

Thanks

@macdonst
Member
macdonst commented Oct 5, 2015

@alexklibisz Hmm, I always thought that push did not work on the emulator but check out this link and report back if this solution works for you:

http://stackoverflow.com/a/23443757/41679

@alexklibisz

@macdonst thanks for the quick response! I will try that. It has definitely worked for me in the past, but I recently had to re-install android SDK/studio/emulator and didn't document the working config I had before :/

I'll try later today and post back results.

@macdonst
Member
macdonst commented Oct 5, 2015

@alexklibisz Sounds great, if this does work for you please close this issue.

@alexklibisz

@macdonst It did indeed solve the problem! Thank you for the pointer!

More specifically, here are the steps I followed:

  • In Android package manager, install the packages:
Android 5.1.1 (API 22)
- Google APIS
- Google APIS Intel x86 Atom Image
  • In android avd configuration, set my emulator target to use the Target: Google APIS (Google Inc)-API Level 22.
  • Rebuild and run app on emulator.

This is of course on top of the other packages I had installed.

Thanks again for the pointer.

@alexklibisz

Closing the issue, see the stackoverflow post linked by @macdonst and my details in the previous comment for resolution.

@alexklibisz alexklibisz closed this Oct 5, 2015
@macdonst
Member
macdonst commented Oct 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment