GCM Docsでは、次のように指定されています。
組み込みのユーザー インターフェイスやメッセージ データのその他の処理は提供されません。GCM は、受信した未加工のメッセージ データを直接 Android アプリケーションに渡すだけで、その処理方法を完全に制御できます。たとえば、アプリケーションは通知を投稿したり、カスタム ユーザー インターフェイスを表示したり、データをサイレントに同期したりします。
ただし、カスタム通知 UI を作成する方法については何もありません。
GCM 通知用の 2 つのボタンを備えた小さなダイアログなどのカスタム UI を作成する方法。gmail と同様に、ステータス バーの通知からメールをアーカイブまたは削除するオプションが提供されます。
コード:
public void onReceive(Context context, Intent intent) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
ctx = context;
String messageType = gcm.getMessageType(intent);
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
.equals(messageType)) {
} else {
sendNotification(intent.getExtras().getString("msg"));
}
setResultCode(Activity.RESULT_OK);
}
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
new Intent(ctx, NotificationsActivity.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
ctx).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("GCM Notification")
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
Notification mNotification = mBuilder.getNotification();
SharedPreferences sp = ctx.getSharedPreferences(
GCMDemoActivity.GCM_NOTIF_PREF, Context.MODE_PRIVATE);
long diff = System.currentTimeMillis()
- sp.getLong("last_gcm_timestamp", 0);
if (diff > TWO_MINUTES) {
mNotification.defaults = Notification.DEFAULT_ALL;
SharedPreferences.Editor editor = sp.edit();
editor.putLong("last_gcm_timestamp", System.currentTimeMillis());
editor.commit();
}
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
}
ありがとうございました