2016-05-15 173 views
0

我想在Android上顯示一個簡單的本地通知消息。這裏是我的代碼,但我無法使它工作。Android - notificationManager.notify不顯示通知

沒有行動:

final Context context = this; 
Intent intent = new Intent(this, MainActivity.class); 
final PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0); 

    Notification n=new Notification.Builder(context) 
            .setContentTitle("Nabeeer?") 
            .setContentText("Iceriiik") 
            .setContentIntent(null) 
            .setContentIntent(pIntent) 
            .setAutoCancel(true) 
            .build(); 

          NotificationManager notificationManager = 
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

          notificationManager.notify(0, n); 

回答

1

您需要的圖標添加到您的通知:

.setSmallIcon(R.drawable.youricon) 

這不是在官方文檔記載:你需要添加一個小圖標,否則the notification won't show