2014-03-26 68 views
0

嗯,我正在推進推送通知功能。它在接收到推送消息之後立即開始意圖。但是我想在用戶點擊通知之後開始這個意圖。點擊推送通知後的開始意圖

那麼,我該怎麼做呢?我怎麼能檢測到用戶點擊收到的消息?

下面是我寫的代碼:

public void onReceive(Context context, Intent intent) { 
    // TODO Auto-generated method stub 
    Log.d("ALERT", "Message Received"); 

    Intent screen2 = new Intent(context, Tela2.class); 
    screen2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    context.startActivity(screen2); 
} 

它的工作好

回答

0

應該創建並顯示通知,並使用掛起的意圖指定從通知開始其活動。

例如:

mNotificationManager = (NotificationManager) 
      context.getSystemService(Context.NOTIFICATION_SERVICE); 

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
      new Intent(context, Tela2.class), 0); 

    NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(this) 
    .setSmallIcon(R.drawable.ic_stat_gcm) 
    .setContentTitle("GCM Notification") 
    .setStyle(new NotificationCompat.BigTextStyle() 
    .bigText(msg)) 
    .setContentText(msg); 

    mBuilder.setContentIntent(contentIntent); 
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 

被點擊的通知時,該代碼就會開始活動。

+0

謝謝,讓我試試吧! – Javanes