当前位置:网站首页>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);边栏推荐
- 【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list
- 荐号 | 对你有恩的人,不要请吃饭来报答
- AI Basics: Graphical Transformer
- VBA 运行时错误‘-2147217900(80040e14):自动化(Automation)错误
- MindSpore:【语音识别】DFCNN网络训练loss不收敛
- [Summary] 1396- 60+ VSCode plugins to create a useful editor
- LocalDate时间生成
- MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
- nlohmann json 使用指南【visual studio 2022】
- SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)
猜你喜欢

【Swords Offer】Swords Offer 17. Print n digits from 1 to the largest

防抖和节流有什么区别,分别用于什么场景?

VS Code 连接SQL Server

部分分类网络性能对比

Basic use of scrapy

MongoDB打破了原则引入SQL?

Scrapy framework is introduced
![[Prometheus] An optimization record of the Prometheus federation [continued]](/img/5d/56e171b7a02584337a0cfe5c731fb2.png)
[Prometheus] An optimization record of the Prometheus federation [continued]

Mysql execution principle analysis

【MindSpore】用coco2017训练Model_zoo上的 yolov4,迭代了两千多batch_size之后报错,大佬们帮忙看看。
随机推荐
阿里云武林头条活动分享
尊重客观事实
requet.getHeader(“token“) 为null
Swiper轮播图片并播放背景音乐
电脑死机的时候,发生了什么?
Read the "Language Model" in one article
CIMC Shilian Dafeitong is the global industrial artificial intelligence AI leader, the world's top AI core technology, high generalization, high robustness, sparse sample continuous learning, industri
Basic use of scrapy
牛客刷题系列之进阶版(组队竞赛,排序子序列,倒置字符串, 删除公共字符,修理牧场)
Does the satellite phone communicate directly with the satellite or through a ground station?
AI Basics: Graphical Transformer
Go 系统收集
跨进程启动后台服务
Difference between Object and Map
[TypeScript]编译配置
MindSpore:mindspore有没有类似tf.GradientTape()用来求解梯度的?
第一次进入小程序判断
又一家公司面试的内容
Delay queue optimization (2)
Recommendation | People who are kind to you, don't repay them by inviting them to eat