当前位置:网站首页>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);
边栏推荐
- Go system collection
- Scrapy framework is introduced
- requet.getHeader(“token“) 为null
- Multiple instances of mysql
- 技术很牛逼,还需要“向上管理”吗?
- 6块钱1斤,日本公司为何来中国收烟头?
- MindSpore:【resnet_thor模型】尝试运行resnet_thor时报Could not convert to
- MindSpore:【JupyterLab】查看数据时报错
- 部分分类网络性能对比
- SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)
猜你喜欢
nlohmann json 使用指南【visual studio 2022】
NXP IMX8QXP replacement DDR model operation process
谷歌AlphaFold近日宣称预测出地球上几乎所有蛋白质结构
JS提升:Promise中reject与then之间的关系
MindSpore:ImageFolderDataset数据读取问题
【hbuilder】运行不了部分项目 , 打开终端 无法输入指令
golang日志库zerolog使用记录
中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
[Summary] 1396- 60+ VSCode plugins to create a useful editor
随机推荐
NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...
VBA 运行时错误‘-2147217900(80040e14):自动化(Automation)错误
What is the difference between a cloud database and an on-premises database?
Chapter 4 Controlling the Execution Flow
The advanced version of the cattle brushing series (search for rotating sorted arrays, inversion of the specified range in the linked list)
How architects grow
- daily a LeetCode 】 【 191. A number of 1
第一次进入小程序判断
VBA runtime error '-2147217900 (80040e14): Automation error
还有三天忙完
浅聊对比学习(Contrastive Learning)第一弹
【Pointing to Offer】Pointing to Offer 22. The kth node from the bottom in the linked list
OneFlow源码解析:Op、Kernel与解释器
[TypeScript]编译配置
启动前台Activity
NXP IMX8QXP更换DDR型号操作流程
scrapy基本使用
Google's AlphaFold claims to have predicted almost every protein structure on Earth
The use of terminal split screen tool Terminalx
MYSQL (Basic) - An article takes you into the wonderful world of MYSQL