2012-12-13 120 views
3

我已經實現了以下在android中顯示一些通知的方法。該方法與developer.android.com教程非常相似,但我的通知不會在4.1或4.0或2.3上顯示。Android通知不會顯示

public void showNotification() { 
    String appname = "App Name"; 
    String title = "Notification Title"; 
    String text = "This is the notification text"; 
    String iconUrl = "http://url.to.image.com/image.png"; 
    Bitmap largeIcon = imageCache.getBitmap(iconUrl); 
    NotificationManager notifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 

    TaskStackBuilder stackBuilder = TaskStackBuilder.from(context); 
    stackBuilder.addParentStack(NewsActivity.class); 
    stackBuilder.addNextIntent(new Intent(context, NewsActivity.class)); 
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context); 
    builder.setContentTitle(title).setContentInfo(appname).setLargeIcon(largeIcon).setContentText(text).setContentIntent(pendingIntent); 

    notifyManager.notify("textid", 123, builder.getNotification()); 
} 

回答

7

A small icon是通知的必需元素。

builder.setSmallIcon(R.drawable.notification_icon); 

這是顯示在狀態欄中的圖標。

0

試試這個:

notifyManager.notify("textid", 123, builder.build());