2014-05-11 62 views
1

我使用的是服務中的代碼,以獲得一個通知,如果我有什麼新的警報,但是當我點擊他們我沒有收到到我想要的看法:Android的通知點擊不工作

if(newAlertCounter > 0) // alert user about new alerts 
{ 
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) 
    .setSmallIcon(R.drawable.ic_action_warning) 
    .setContentTitle(newAlertCounter + " new flood alerts!") 
    .setContentText("Tap to see where in your vecinity."); 

    // Sets an ID for the notification 
    int mNotificationId = 001; 
    // Gets an instance of the NotificationManager service 
    NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    // Builds the notification and issues it. 
    mNotifyMgr.notify(mNotificationId, mBuilder.build()); 

    // notification click action 
    Intent notificationIntent = new Intent(this, ViewAlertsActivity.class); 

    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

    mBuilder.setContentIntent(resultPendingIntent); 
} 

它顯示,但它不可點擊,所以這是什麼錯?

回答

1

mNotifyMgr.notify(mNotificationId, mBuilder.build()); 

mBuilder.setContentIntent(resultPendingIntent); 
1

移動你的

mNotifyMgr.notify(mNotificationId, mBuilder.build()); 

mBuilder.setContentIntent(resultPendingIntent); 

當你調用.build()創建無content intent通知。 (沒有,它不會被之後,因爲其將被髮送到通知系統中的對象將是Notification不是Builder加)


if(newAlertCounter > 0) // alert user about new alerts 
{ 
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) 
    .setSmallIcon(R.drawable.ic_action_warning) 
    .setContentTitle(newAlertCounter + " new flood alerts!") 
    .setContentText("Tap to see where in your vecinity."); 

    // Sets an ID for the notification 
    int mNotificationId = 001; 
    // Gets an instance of the NotificationManager service 
    NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    // Builds the notification and issues it. 


    // notification click action 
    Intent notificationIntent = new Intent(this, ViewAlertsActivity.class); 

    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

    mBuilder.setContentIntent(resultPendingIntent); 

    mNotifyMgr.notify(mNotificationId, mBuilder.build()); 
}