index.html 에서 푸시 등록하는 부분 :
function onDeviceReady() {
var pushNotification;
pushNotification = window.plugins.pushNotification;
pushNotification.unregister(function() { },errorHandler);
pushNotification.register(successHandler, errorHandler,{"senderID":"[플젝아이디]","ecb":"onNotificationGCM"});
$("#app-status-ul").append('<li>deviceready event received</li>');
}
onNotificationGCM = function(e) {
//...
};
PushPlugin.java
@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
boolean result = false;
Log.v(TAG, "execute: action=" + action);
if (REGISTER.equals(action)) {
Log.v(TAG, "execute: data=" + data.toString());
try {
JSONObject jo = data.getJSONObject(0);
gWebView = this.webView;
Log.v(TAG, "execute: jo=" + jo.toString());
gECB = (String) jo.get("ecb");
gSenderID = (String) jo.get("senderID");
Log.v(TAG, "execute: ECB=" + gECB + " senderID=" + gSenderID);
GCMRegistrar.register(getApplicationContext(), gSenderID);
result = true;
callbackContext.success();
} catch (JSONException e) {
Log.e(TAG, "execute: Got JSON Exception " + e.getMessage());
result = false;
callbackContext.error(e.getMessage());
}
if ( gCachedExtras != null) {
Log.v(TAG, "sending cached extras");
sendExtras(gCachedExtras);
gCachedExtras = null;
}
} else if (UNREGISTER.equals(action)) {
GCMRegistrar.unregister(getApplicationContext());
Log.v(TAG, "UNREGISTER");
result = true;
callbackContext.success();
} else {
result = false;
Log.e(TAG, "Invalid action : " + action);
callbackContext.error("Invalid action : " + action);
}
return result;
}
/*
* Sends a json object to the client as parameter to a method which is defined in gECB.
*/
public static void sendJavascript(JSONObject _json) {
String _d = "javascript:" + gECB + "(" + _json.toString() + ")";
Log.v(TAG, "sendJavascript: " + _d);
if (gECB != null && gWebView != null) {
gWebView.sendJavascript(_d);
//gWebView.loadUrl("javascript:" + _d);
}
}
안녕하세요. 폰갭 Cordova를 사용한 웹앱을 개발중인데요 (안드로이드 버전만 개발하고 있습니다.),
앱을 구동하게 되면 push plugin을 통해 등록을 하는데 (상단 소스)에서 onNotificationGCM을 호출되어야 하는데 호출이 안 되어서, PushPlugin을 보니 Logcat에는 execute: ECB=onNotificationGCM senderID=[플젝아이디] 이후에 GCMRegistrar registering app ~ 이후로는 로그에도 특별히 찍히는 게 없습니다.
플젝아이디는 실제로 개발자 콘솔에 등록 및 활성화가 된 상태이구요, 특이한 것은
갤럭시 S4미니(4.4.4), 베가 아이언(4.4.2), LG G Pro등 다 되는데 유독 갤럭시 그랜드 맥스(4.4.4)에서만 이런 현상이 발생합니다. 하필 이것도 고객님 폰인데다가 거기다 전에는(실제 출시용 프로젝트ID로 바꾸기 전) 정상적으로 되었던 거라 고객분께도 어떻게 설명 드려야할지 난감하기도 하네요;;
이 외에 확인해야 하는 부분이나 팁이 있으면 알려주시면 감사드리겠습니다.