首页 文章

如何通过下拉菜单中的通知将活动带到前面?

提问于
浏览
1

我正在使用通知(使用前台服务)的应用程序 .

用例如下:

  • 如果应用程序的活动被终止,则单击通知的图标时,将创建活动并将其置于前台 .

  • 如果应用程序的活动不可见,则单击通知的图标时,活动将简单地转到前台 .

为了重新创建/将活动带到前台,我在前台服务中使用以下广播接收器:

private static class MyBroadcastReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent intent = new Intent(context,MainActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            .setAction("android.intent.action.MAIN")
            .addCategory("android.intent.category.LAUNCHER");
        context.startActivity(sIntent);
    }
}

所需的动作与Android手机上的默认音乐播放器非常相似,即:当点击图标时,它的活动只是被带到前台(或者重新创建并在之前被杀死时被带到前台)

这是三星S4的截图

Teh screenshot

  • 首次通知来自usb - 我们不关心它

  • 秒通知是我的申请 - when clicking on the icon the activity gets created but not brought to foreground (用户必须刷回菜单才能看到活动)

How can I bring it to front without the additional swipe-back-menu? (与音乐播放器应用程序的工作方式类似?

PS:最低Android SDK版本为16

1 回答

  • 1

    据我所知,没有可能将您的活动带到通知菜单前 . 但您可以使用以下命令自动关闭菜单:

    Intent i = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 
    context.sendBroadcast(i);
    

相关问题