我的Android應用程序和服務器已配置爲接收和發送推送通知。我的應用程序完美收到通知,並在LogCat中顯示我的應用程序是否在後臺打開,或者不在運行。但是,我遇到問題需要顯示。無論我做什麼,我都無法將它顯示在通知中心,或者以警報的形式出現,讓手機振動或發出聲音。已收到但未顯示的GCM通知
我錯過了什麼?我從這裏使用GCM插件:https://github.com/marknutter/GCM-Cordova
我試過讓它使用NotificationCompat發送通知,但我一直不成功。
- >從GCM JSON傳遞給這個函數...
@Override
protected void onMessage(Context context, Intent intent) {
Log.d(TAG, "onMessage - context: " + context);
// Extract the payload from the message
Bundle extras = intent.getExtras();
if (extras != null) {
try
{
Log.v(ME + ":onMessage extras ", extras.getString("message"));
JSONObject json;
json = new JSONObject().put("event", "message");
// My application on my host server sends back to "EXTRAS" variables message and msgcnt
// Depending on how you build your server app you can specify what variables you want to send
json.put("message", extras.getString("message"));
json.put("msgcnt", extras.getString("msgcnt"));
Log.v(ME + ":onMessage ", json.toString());
GCMPlugin.sendJavascript(json);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("TEST")
.setContentText("TEST");
// Send the MESSAGE to the Javascript application
}
catch(JSONException e)
{
Log.e(ME + ":onMessage", "JSON exception");
}
}
}
的目標顯然是讓測試通知顯示,然後剝離該消息出來的JSON的。 – centree 2013-05-09 16:41:41