76版 打开权限设置工具类
This commit is contained in:
parent
80a257273b
commit
58a3f502da
@ -38,8 +38,8 @@ android {
|
|||||||
applicationId "com.arpa.hndahesudintocctmsdriver"
|
applicationId "com.arpa.hndahesudintocctmsdriver"
|
||||||
minSdkVersion 24
|
minSdkVersion 24
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode 75
|
versionCode 76
|
||||||
versionName "3.4.5"
|
versionName "3.4.6"
|
||||||
flavorDimensions "CHANNEL_VALUE"
|
flavorDimensions "CHANNEL_VALUE"
|
||||||
flavorDimensions "app_icon"
|
flavorDimensions "app_icon"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
@ -0,0 +1,112 @@
|
|||||||
|
package com.dahe.mylibrary.utils;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName PermissionUtils
|
||||||
|
* @Author john
|
||||||
|
* @Date 2024/12/19 14:59
|
||||||
|
* @Description TODO
|
||||||
|
*/
|
||||||
|
public class PermissionUtils {
|
||||||
|
|
||||||
|
// 私有静态实例,防止被外部实例化
|
||||||
|
private static PermissionUtils instance;
|
||||||
|
|
||||||
|
// 私有构造方法,防止通过 new 关键字创建实例
|
||||||
|
private PermissionUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取单例实例
|
||||||
|
public static PermissionUtils getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
synchronized (PermissionUtils.class) {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new PermissionUtils();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据不同手机机型跳转到权限设置页面
|
||||||
|
*
|
||||||
|
* @param context 上下文
|
||||||
|
*/
|
||||||
|
public void goToAppPermissionSettings(Context context) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
if (Build.FINGERPRINT.startsWith("Huawei") || Build.BRAND.startsWith("Huawei")) {
|
||||||
|
// 华为手机
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
|
Uri uri = Uri.fromParts("package", context.getPackageName(), null);
|
||||||
|
intent.setData(uri);
|
||||||
|
} else if (Build.FINGERPRINT.startsWith("Xiaomi") || Build.BRAND.startsWith("Xiaomi")) {
|
||||||
|
// 小米手机
|
||||||
|
intent.setAction(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
|
||||||
|
Uri uri = Uri.parse("package:" + context.getPackageName());
|
||||||
|
intent.setData(uri);
|
||||||
|
} else if (Build.BRAND.equals("Meizu")) {
|
||||||
|
// 魅族手机
|
||||||
|
intent.setAction("com.meizu.safe.security.SHOW_APPSEC");
|
||||||
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
intent.putExtra("packageName", context.getPackageName());
|
||||||
|
} else if (Build.FINGERPRINT.startsWith("OPPO") || Build.BRAND.startsWith("OPPO")) {
|
||||||
|
// OPPO手机
|
||||||
|
try {
|
||||||
|
String pkgName = context.getPackageName();
|
||||||
|
String className = "com.coloros.safecenter.permission.PermissionManagerActivity";
|
||||||
|
intent.setClassName("com.coloros.safecenter", className);
|
||||||
|
intent.putExtra("packageName", pkgName);
|
||||||
|
intent.putExtra("appName", context.getResources().getString(context.getApplicationInfo().labelRes));
|
||||||
|
intent.putExtra("opType", "4"); // 4 表示权限管理页面
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 如果找不到OPPO的特定页面,则使用通用页面
|
||||||
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
|
Uri uri = Uri.fromParts("package", context.getPackageName(), null);
|
||||||
|
intent.setData(uri);
|
||||||
|
}
|
||||||
|
} else if (Build.FINGERPRINT.startsWith("vivo") || Build.BRAND.startsWith("vivo")) {
|
||||||
|
// vivo手机
|
||||||
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
|
Uri uri = Uri.fromParts("package", context.getPackageName(), null);
|
||||||
|
intent.setData(uri);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
||||||
|
} else if (Build.BRAND.equals("samsung")) {
|
||||||
|
// 三星手机
|
||||||
|
try {
|
||||||
|
String pkgName = context.getPackageName();
|
||||||
|
Intent intent2 = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
|
||||||
|
intent2.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
intent2.setData(Uri.parse("package:" + pkgName));
|
||||||
|
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent2.putExtra("com.android.providers.media.EXTRA_APP_PACKAGE", pkgName);
|
||||||
|
context.startActivity(intent2);
|
||||||
|
return; // 使用三星特定的页面,不需要继续执行通用代码
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 如果三星特定页面失败,则使用通用页面
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 其他手机使用通用页面
|
||||||
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
|
Uri uri = Uri.fromParts("package", context.getPackageName(), null);
|
||||||
|
intent.setData(uri);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 低于Android 6.0(M)的版本,使用通用页面
|
||||||
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
|
Uri uri = Uri.fromParts("package", context.getPackageName(), null);
|
||||||
|
intent.setData(uri);
|
||||||
|
}
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user