Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking internet connectivity before calling register #497

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/android/com/plugin/gcm/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.google.android.gcm.GCMRegistrar;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
Expand Down Expand Up @@ -61,8 +64,11 @@ public boolean execute(String action, JSONArray data, CallbackContext callbackCo
gSenderID = (String) jo.get("senderID");

Log.v(TAG, "execute: ECB=" + gECB + " senderID=" + gSenderID);

GCMRegistrar.register(getApplicationContext(), gSenderID);

if (isNetworkAvailable()) {
GCMRegistrar.register(getApplicationContext(), gSenderID);
}

result = true;
callbackContext.success();
} catch (JSONException e) {
Expand Down Expand Up @@ -232,7 +238,14 @@ else if (strValue.startsWith("["))
}
return null;
}


private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

public static boolean isInForeground()
{
return gForeground;
Expand Down