私のアンドロイドアプリとサーバーは、プッシュ通知を送受信するように構成されています。私のアプリは完全に通知を受け取り、アプリがバックグラウンドで開いているか、正常に実行されていないかに関係なく、LogCat に表示されます。ただし、表示に問題があります。何をしても、通知センターに表示されたり、電話を振動させたり音を鳴らしたりするアラートとして表示されたりすることはありません。
私は何が欠けていますか?ここから 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");
}
}
}