ユーザーがいつ通知をクリックしたかを知りたいので、サービスに次のコードを追加します
RemoteViews remoteviews = new RemoteViews("com.eample.triplogger", R.layout.custom_notifications);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(GcmIntentService.this)
.setContent(remoteviews)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setOngoing(true);
PendingIntent contentIntent = PendingIntent.getActivity(this, PENDING_TRIPS_NOTIFICATION_ID,
new Intent(this, MainActivity.class).putExtra("is_log", true), Intent.FLAG_ACTIVITY_CLEAR_TOP);
remoteviews.setOnClickPendingIntent(R.layout.custom_notifications, contentIntent);
mBuilder.setContentIntent(contentIntent);//click on whole notification action
mNotificationManager.notify(PENDING_TRIPS_NOTIFICATION_ID, mBuilder.build());
ユーザーが通知をクリックすると、私の主なアクティビティは開いていますが、ユーザーが通知をクリックしたときに呼び出されるコードの一部を取得したいです(seOnclickListener()の場合はonClick(View v)が呼び出されます。コールバックするものと同じです) setOnClickPendingIntent() に対して呼び出します。