当前位置:网站首页>Start foreground Activity
Start foreground Activity
2022-07-30 19:20:00 【rookie xiaowang】
1.manifest configuration permissions
2. Permission to open the floating window
public static boolean checkFloatPermission(Context context) {if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)//4.4-5.1return true;if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {//6.0try {Class cls = Class.forName("android.content.Context");Field declaredField = cls.getDeclaredField("APP_OPS_SERVICE");declaredField.setAccessible(true);Object obj = declaredField.get(cls);if (!(obj instanceof String)) {return false;}String str2 = (String) obj;obj = cls.getMethod("getSystemService", String.class).invoke(context, str2);cls = Class.forName("android.app.AppOpsManager");Field declaredField2 = cls.getDeclaredField("MODE_ALLOWED");declaredField2.setAccessible(true);Method checkOp = cls.getMethod("checkOp", Integer.TYPE, Integer.TYPE, String.class);int result = (Integer) checkOp.invoke(obj, 24, Binder.getCallingUid(), context.getPackageName());return result == declaredField2.getInt(cls);} catch (Exception e) {return false;}} else {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//8AppOpsManager appOpsMgr = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);if (appOpsMgr == null)return false;int mode = appOpsMgr.checkOpNoThrow("android:system_alert_window", android.os.Process.myUid(), context.getPackageName());return Settings.canDrawOverlays(context) || mode == AppOpsManager.MODE_ALLOWED || mode == AppOpsManager.MODE_IGNORED;} else {return Settings.canDrawOverlays(context);}}}if(!(checkFloatPermission(this))){Toast.makeText(getApplicationContext(),"Please set the floating window permission for the software, otherwise it will not work normally!",Toast.LENGTH_SHORT).show();Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);startActivity(intent);}3. Start activity
Intent intent1 = new Intent(getApplicationContext(), MainActivity.class);intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);getApplicationContext().startActivity(intent1);边栏推荐
猜你喜欢

Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group

MindSpore:【JupyterLab】按照新手教程训练时报错

After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...

- daily a LeetCode 】 【 191. A number of 1

第十七届“振兴杯”全国青年 职业技能大赛——计算机程序设计员(云计算平台与运维)参赛回顾与总结

kotlin的by lazy

Encapsulates a console file selector based on inquirer
![[TypeScript]编译配置](/img/ac/64ebd33de977e35620dbc18d2adfad.png)
[TypeScript]编译配置

解决终极bug,项目最终能顺利部署上线。

Win11如何更改默认下载路径?Win11更改默认下载路径的方法
随机推荐
MindSpore:Cifar10Dataset‘s num_workers=8, this value is not within the required range of [1, cpu_thr
C# wpf 无边框窗口添加阴影效果
跨域问题的解决方法
架构师如何成长
Object和Map的区别
【每日一道LeetCode】——191. 位1的个数
谷歌AlphaFold近日宣称预测出地球上几乎所有蛋白质结构
[Prometheus] An optimization record of the Prometheus federation [continued]
Golang logging library zerolog use record
中集世联达飞瞳全球工业人工智能AI领军者,全球顶尖AI核心技术高泛化性高鲁棒性稀疏样本持续学习,工业级高性能成熟AI产品规模应用
LocalDate时间生成
Chapter 14 Type Information
DM8: Single database and single instance to build a local data guard service
【剑指 Offe】剑指 Offer 18. 删除链表的节点
NXP IMX8QXP replacement DDR model operation process
实体中增加操作方法
【MindSpore1.2.0-rc1产品】num_workers问题
MindSpore:【Resolve node failed】解析节点失败的问题
What is the difference between a cloud database and an on-premises database?
Encapsulates a console file selector based on inquirer