Skip to content

Commit

Permalink
Update GCM registration code to use the latest API's (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
yinfeiru authored and Sergio Alonso Fernández committed Sep 2, 2016
1 parent 4451279 commit e9b48ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Expand Up @@ -36,8 +36,8 @@ android {
// pom! If you need a transitive dependency in the library, you'll
// have to change the bit in uploadArchives that marks all dependencies as optional.
dependencies {
compile 'com.google.android.gms:play-services-base:[3.1,)'
compile 'com.google.android.gms:play-services-gcm:[3.1,)'
compile 'com.google.android.gms:play-services-base:[7.5.0,)'
compile 'com.google.android.gms:play-services-gcm:[7.5.0,)'
}

android.libraryVariants.all { variant ->
Expand Down
Expand Up @@ -11,11 +11,12 @@
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.android.gms.iid.InstanceID;
import com.mixpanel.android.util.Base64Coder;
import com.mixpanel.android.util.RemoteService;
import com.mixpanel.android.util.HttpService;
import com.mixpanel.android.util.RemoteService;

import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -344,7 +345,7 @@ private void runGCMRegistration(String senderID) {
// Google Play Services version and requiring Java 1.7
// in the next major library release.
try {
final int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext);
final int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mContext);
if (resultCode != ConnectionResult.SUCCESS) {
Log.i(LOGTAG, "Can't register for push notifications, Google Play Services are not installed.");
return;
Expand All @@ -354,9 +355,8 @@ private void runGCMRegistration(String senderID) {
return;
}


final GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(mContext);
registrationId = gcm.register(senderID);
InstanceID instanceID = InstanceID.getInstance(mContext);
registrationId = instanceID.getToken(senderID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
} catch (IOException e) {
Log.i(LOGTAG, "Exception when trying to register for GCM", e);
return;
Expand Down Expand Up @@ -495,7 +495,7 @@ private JSONObject getDefaultEventProperties()

try {
try {
final int servicesAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext);
final int servicesAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mContext);
switch (servicesAvailable) {
case ConnectionResult.SUCCESS:
ret.put("$google_play_services", "available");
Expand Down

0 comments on commit e9b48ea

Please sign in to comment.