2016-03-24 10 views
2

通知をクリックした後、いくつかのメソッドを呼び出す必要があります。私の通知には、ブラウザを開くpendingIntentがあります。しかし、私はユーザーがそれをクリックした後に他の何かをしなければならない。ああ、私はGCMからの通知を受け取ることを認めなければなりません(プッシュ)。通知のクリックをどのように捕捉できますか?

Intent intent; 
intent = new Intent(Intent.ACTION_VIEW); 
intent.setData(Uri.parse(urlString)); 
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) 
       .setSmallIcon(R.drawable.ic_launcher) 
       .setLargeIcon(mBitmap) 
       .setContentTitle(title) 
       .setDefaults(Notification.DEFAULT_ALL) 
       .setContentText(body) 
       .setAutoCancel(true); 

     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 

     Notification myNotification = notificationBuilder.build(); 
     myNotification.setLatestEventInfo(getBaseContext(), title, body, pendingIntent); 

     NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(TAG, myNotification); 
+0

あなたは通知コード –

+0

@SajalChoukseコードが追加されました)を追加してください)) – PerSpiKyliaTor

+0

「あなたがそれをクリックした後に他の何かをする」とはどういう意味ですか?ブラウザを起動する前に他の操作をしなければならないという意味ですか? – curob

答えて

0

次のようContentIntentを指定する必要があり、通知自体(ないアクション)のクリックを処理するには:

notificationBuilder.setContentIntent(PendingIntent.getActivity(
       context, 
       0, 
       new Intent(context, YourActivity.class) 
        .putExtra("extra_something", something) 
        .setData(Uri.parse("pass an uri if needed")), 
       PendingIntent.FLAG_UPDATE_CURRENT 
     )) 

はそれがお役に立てば幸いです。

関連する問題