我已经有了Android的工作状态栏通知,但要创建它,我必须设置一个Activity才能打开它.我不希望任何活动开放; 但是,这个小项目根本不需要接口.
mNotificationManager = (NotificationManager) aContext
.getApplicationContext().getSystemService(
Context.NOTIFICATION_SERVICE);
// Create the pending intent, which is basically NOW.
PendingIntent contentIntent = PendingIntent
.getActivity(aContext, 1, new Intent(aContext, BlankActivity.class),
PendingIntent.FLAG_CANCEL_CURRENT);
// Create notification
notificationBuilder = new NotificationCompat.Builder(aContext)
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_launcher) // required for launch
.setTicker("Downloading video...") // required for launch
.setWhen(System.currentTimeMillis()) // should be set for now.
.setContent(remoteView);
Run Code Online (Sandbox Code Playgroud)
BlankActivity
它听起来像是一个没有内容的活动,在被打开时关闭.但它仍然显示在最近打开的窗口列表中.我无法将其设置为null.
有没有办法可以避免设置状态通知的意图?
PendingIntent
在这种情况下你不需要.只需将它设置null
在setContentIntent()
可能的帮助.
另一种方式可以
PendingIntent contentIntent = PendingIntent.getActivity(aContext(),0,new Intent(),PendingIntent.FLAG_CANCEL_CURRENT);
Run Code Online (Sandbox Code Playgroud)
试试这个.
归档时间: |
|
查看次数: |
679 次 |
最近记录: |