【发布时间】:2013-08-30 14:52:02
【问题描述】:
我试图创建一个通知,通过单击它来启动一个活动,并且你不能滑动它。
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("DroidSchool")
.setContentText("DroidSchool l\u00E4uft im Hintergrund...");
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, Intent.FLAG_FROM_BACKGROUND);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int mId = 1234567890;
mNotificationManager.notify(mId, mBuilder.build());
上面的代码显示了通知,但是当我点击它时没有任何反应,你可以将它滑开。
【问题讨论】:
-
问题主要在于意图......
-
如果它是不可破坏的,那你怎么能把它移除呢?
-
应用程序关闭时@bofredo。我的意思是例如像 avast 通知
-
没试过,但也许a foreground service是你要找的?
-
如果您使用带有通知的服务,您应该使用 ForegroundService !!
标签: java android android-intent notifications android-pendingintent