当前位置:网站首页>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);边栏推荐
- OneFlow source code analysis: Op, Kernel and interpreter
- Entering the applet for the first time
- Recommendation | People who are kind to you, don't repay them by inviting them to eat
- VBA batch import Excel data into Access database
- kotlin的by lazy
- What is a RESTful API?
- 技术很牛逼,还需要“向上管理”吗?
- VS Code connects to SQL Server
- Win11如何更改默认下载路径?Win11更改默认下载路径的方法
- 第一次进入小程序判断
猜你喜欢

SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)

Golang logging library zerolog use record

natural language processing nltk

Win11如何更改默认下载路径?Win11更改默认下载路径的方法

What is the difference between a cloud database and an on-premises database?

【网站放大镜效果】两种方式实现
![[TypeScript]编译配置](/img/ac/64ebd33de977e35620dbc18d2adfad.png)
[TypeScript]编译配置

MySql中@符号的使用

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

浅聊对比学习(Contrastive Learning)第一弹
随机推荐
What is the difference between a cloud database and an on-premises database?
VBA batch import Excel data into Access database
MySql中@符号的使用
Golang logging library zerolog use record
【PHPWord】Quick Start of PHPWord in PHPOffice Suite
VS Code 连接SQL Server
[Prometheus] An optimization record of the Prometheus federation [continued]
scrapy基本使用
2种手绘风格效果比较,你更喜欢哪一种呢?
阿里云武林头条活动分享
kotlin的by lazy
Correct pose of Vulkan open feature
Recommendation | People who are kind to you, don't repay them by inviting them to eat
node封装一个控制台进度条插件
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.解决方法
MindSpore:【JupyterLab】按照新手教程训练时报错
牛客刷题系列之进阶版(组队竞赛,排序子序列,倒置字符串, 删除公共字符,修理牧场)
第4章 控制执行流程
Does the satellite phone communicate directly with the satellite or through a ground station?
【科普】无线电波怎样传送信息?