当前位置:网站首页>启动前台Activity
启动前台Activity
2022-07-30 18:58:00 【菜鸟xiaowang】
1.manifest配置权限
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<permission android:name="android.permission.SYSTEM_ALERT_WINDOW"
android:label="@string/permlab_systemAlertWindow"
android:description="@string/permdesc_systemAlertWindow"
android:protectionLevel="signature|preinstalled|appop|pre23|development" />
2.开启悬浮窗权限
public static boolean checkFloatPermission(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)//4.4-5.1
return true;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {//6.0
try {
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) {//8
AppOpsManager 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(),"请给软件设置悬浮窗权限,否则无法正常使用!",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
startActivity(intent);
}
3.启动activity
Intent intent1 = new Intent(getApplicationContext(), MainActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent1);
边栏推荐
- 自然语言处理nltk
- 博纳影通过IPO注册:阿里腾讯是股东 受疫情冲击明显
- natural language processing nltk
- node封装一个控制台进度条插件
- 高并发秒杀项目总结
- Pytorch foundation -- tensorboard use (1)
- 你好,我的新名字叫“铜锁/Tongsuo”
- What is the value of biomedical papers? How to translate the papers into Chinese and English?
- ROS 节点初始化步骤、topic/service创建及使用
- Vulkan开启特征(feature)的正确姿势
猜你喜欢
Mysql执行原理剖析
natural language processing nltk
中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
【Prometheus】Prometheus联邦的一次优化记录[续]
Recommended Books | Recommend 3 database books with rave reviews
The use of @ symbol in MySql
【PHPWord】Quick Start of PHPWord in PHPOffice Suite
2种手绘风格效果比较,你更喜欢哪一种呢?
国轩高科瑞交所上市:募资近7亿美元 为瑞士今年最大融资项目
固定资产可视化智能管理系统
随机推荐
MySQL data types
终端分屏工具Terminalx的使用
【Swords Offer】Swords Offer 17. Print n digits from 1 to the largest
【剑指 Offer】剑指 Offer 22. 链表中倒数第k个节点
高精度加法
解决终极bug,项目最终能顺利部署上线。
Recommendation | People who are kind to you, don't repay them by inviting them to eat
Critical Reviews | 南农邹建文组综述全球农田土壤抗生素与耐药基因分布
[Summary] 1396- 60+ VSCode plugins to create a useful editor
scrapy基本使用
Basic use of scrapy
【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list
requet.getHeader("token") is null
Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group
固定资产可视化智能管理系统
ctf.show_web5
[Use of Qt Designer tool]
After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
- daily a LeetCode 】 【 191. A number of 1
延时队列优化 (2)