简体   繁体   English

如何从后台服务的全屏意图通知 Android 打开活动

[英]How to open activity from background service's full screen intent notification Android

Project min API KitKat(19), project target API Android 10(30)项目最小 API KitKat(19),项目目标 API Android 10(30)

I am trying to do something to the effect of launching an activity from my background service.我正在尝试做一些事情来从我的后台服务启动一个活动。 I understand that launching an activity from a background service is explicitly impossible as of API 29.我知道从 API 29 开始,从后台服务启动活动显然是不可能的。

However, would it be possible to create a full-screen intent notification and a broadcast receiver for that notification which automatically opens an activity from my app?但是,是否可以为该通知创建一个全屏意图通知和一个广播接收器,从而自动从我的应用程序中打开一个活动? Or, will the user still have to click on the full-screen notification before the activity could be launched?或者,在启动活动之前,用户是否仍需要单击全屏通知?

If automatically launching an activity from a broadcast receiver in this way is possible, how would it be done?如果以这种方式从广播接收器自动启动活动是可能的,它将如何完成?

Thank you!谢谢!

You can open activity from the background by adding "SYSTEM_ALERT_WINDOW" permission to the manifest and ask for user permission once when the app opened the first time by calling startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION));您可以通过在清单中添加"SYSTEM_ALERT_WINDOW"权限从后台打开活动,并在应用第一次打开时通过调用startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)); somewhere in your app and granting permission to your app.在您的应用程序中的某个位置并授予您的应用程序权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM