我只想在用户交互期间在状态栏上制作一个自定义通知。
我使用这段代码:
Notification notification = new Notification(getBatteryStateResource(percent,status), "notify",System.currentTimeMillis());
notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
notification.contentView = new RemoteViews(mContext.getPackageName(), R.layout.statusbar);
Intent intent = new Intent(mContext, Activity.class);
PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
notification.contentIntent=contentIntent;
notification.contentView.setOnClickPendingIntent(R.id.imageView, anotherContentIntent);
NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(42, notification);
此代码仅适用于 android 4 智能手机。在平板电脑上,每次点击通知的imageView,系统都会删除通知。
相反,在 Android 2.3 和 2.2 上,“anotherContentIntent”不启动并且只启动“contentIntent”,为什么?
非常感谢....