如何制作状态栏通知,什么也不做,无处可去?

1 notifications android

我已经有了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.

有没有办法可以避免设置状态通知的意图?

Sac*_*tte 5

PendingIntent在这种情况下你不需要.只需将它设置nullsetContentIntent() 可能的帮助.

另一种方式可以

PendingIntent contentIntent = PendingIntent.getActivity(aContext(),0,new Intent(),PendingIntent.FLAG_CANCEL_CURRENT);
Run Code Online (Sandbox Code Playgroud)

试试这个.