1

我的代码如下。代码执行时,会显示通知,但不会显示远程视图。

我的意思是我在通知中看不到 R.layout.layout_update_bar 。

mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotification = new Notification(R.drawable.close_icon,"Pet Parrot", System.currentTimeMillis());
mNotification.defaults = 4;

mRemoteView = new RemoteViews(getPackageName(), R.layout.layout_update_bar);
mNotification.contentView = mRemoteView;
mNotification.contentView.setProgressBar(R.id.progress,100,44,false);
mNotification.contentView.setTextViewText(R.id.title, "Siddharth" + "2km -> 20km");
//mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
CharSequence contentTitle = "download";
Intent notificationIntent = new Intent(this,PhotoSaSa.class);
PendingIntent contentIntent = PendingIntent
    .getActivity(this, 0, notificationIntent, 0);
mNotification.setLatestEventInfo(this, contentTitle,"", contentIntent);

mNotifyManager.notify(1, mNotification);
4

2 回答 2

1

调用会setLatestEventInfo()覆盖您的自定义contentView。将其移至第 3 行,或者更好的是,切换到Notification.Builderapi。

于 2013-10-13T04:09:14.553 回答
-1

尝试在您的代码中设置 notification.icon 。仅设置 notification.contentView 不能成功在通知中看到它。

于 2016-10-27T01:14:39.563 回答