我已经实现了以下方法在android中显示一些通知。该方法与developer.android.com教程非常相似,但我的通知不会出现在4.1或4.0或2.3上。
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());
}
答案 0 :(得分:6)
答案 1 :(得分:0)
试试这个:
notifyManager.notify("textid", 123, builder.build());