标签:man san app应用 except style out 日期时间 gets isp
private void toSetting() {
Intent localIntent = new Intent();
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= 9) {
localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
localIntent.setData(Uri.fromParts("package", getPackageName(), null));
}
startActivity(localIntent);
}
/**
* 启动app应用的信息设置
*/
public static void startAppSettings(Context mContext) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + mContext.getPackageName()));
mContext.startActivity(intent);
}public static int getOsUid(Context context) {
int uid = 0;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ApplicationInfo appinfo = context.getApplicationInfo();
List<ActivityManager.RunningAppProcessInfo> run = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo runningProcess : run) {
if ((runningProcess.processName != null) && runningProcess.processName.equals(appinfo.processName)) {
uid = runningProcess.uid;
break;
}
}
return uid;
}
/**
* 获取通知栏开关的状态:分8.0系统之上和8.0系统之下
* des:
*/
public static boolean isNoticeEnable(Context context) {
boolean isNoticeEnable = false;
String pkg = context.getPackageName();
int uid = 0x011111;//自己获取
if (Build.VERSION.SDK_INT >= 26) {//8.0系统之上
isNoticeEnable=isNoticeEnableV26(context, uid);
} else {
isNoticeEnable=isNoticeEnableV19(context, uid);
}
return isNoticeEnable;
}
/**
* des:8.0之后,提供给APP适用的的NotificationManager 类中有INotificationManager对象,最终我们通过反射获取通知栏开关
*/
private static boolean isNoticeEnableV26(Context context, int uid) {
try {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Method sServiceField = notificationManager.getClass().getDeclaredMethod("getService");
sServiceField.setAccessible(true);
Object sService = sServiceField.invoke(notificationManager);
Method method = sService.getClass().getDeclaredMethod("areNotificationsEnabledForPackage", String.class, Integer.TYPE);
method.setAccessible(true);
return (boolean) method.invoke(sService, context.getPackageName(), uid);
} catch (Exception e) {
return true;
}
}
/**
* des:针对8.0之前设备,通过AppOpsManager的checkOpNoThrow方法获取。
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean isNoticeEnableV19(Context context, int uid) {
try {
String CHECK_OP_NO_THROW = "checkOpNoThrow";
String OP_POST_NOTIFICATION = "OP_POST_NOTIFICATION";
Class appOpsClass = null;
AppOpsManager mAppOps = null;
mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
appOpsClass = Class.forName(AppOpsManager.class.getName());
Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE,
Integer.TYPE, String.class);
Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION);
int value = (Integer) opPostNotificationValue.get(Integer.class);
return ((Integer) checkOpNoThrowMethod.invoke(mAppOps, value, uid, context.getPackageName()) == AppOpsManager.MODE_ALLOWED);
} catch (Exception e) {
return true;
}
}
/**
* 针对8.0及以上设备,发现上述方式不生效。查询系统设置源码,在NotificationBackend类中发现获取通知栏状态改到INotificationManager中了
*/
private boolean getNotificationsBanned(String pkg, int uid) {
try {
final boolean enabled = sINM.areNotificationsEnabledForPackage(pkg, uid);
return !enabled;
} catch (Exception e) {
Log.w(TAG, "Error calling NoMan", e);
return false;
}
}
/**
* 打开允许通知的设置页(跳到的是全部通知的页面,不是很理想)
*/
private void goToNotificationSetting(Context context) {
Intent intent = new Intent();
if (Build.VERSION.SDK_INT >= 26) { // android 8.0引导
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName());
} else if (Build.VERSION.SDK_INT >= 21) { // android 5.0-7.0
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
intent.putExtra("app_package", context.getPackageName());
intent.putExtra("app_uid", context.getApplicationInfo().uid);
} else { // 其他
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.setData(Uri.fromParts("package", context.getPackageName(), null));
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
========
6. ACTION_APPLICATION_DEVELOPMENT_SETTINGS : // 跳转开发人员选项界面
标签:man san app应用 except style out 日期时间 gets isp
原文地址:https://www.cnblogs.com/awkflf11/p/9484242.html