Intent之跳转总结
Posted awkflf11
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Intent之跳转总结相关的知识,希望对你有一定的参考价值。
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 : // 跳转开发人员选项界面Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
startActivity(intent);
7. ACTION_APPLICATION_SETTINGS : // 跳转应用程序列表界面
Intent intent = new Intent(Settings.ACTION_APPLICATION_SETTINGS);
startActivity(intent);
或者:
ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS // 跳转到应用程序界面【所有的】
Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
startActivity(intent);
或者:
ACTION_MANAGE_APPLICATIONS_SETTINGS :// 跳转 应用程序列表界面【已安装的】
Intent intent = new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
startActivity(intent);
8. ACTION_BLUETOOTH_SETTINGS : // 跳转系统的蓝牙设置界面
Intent intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
startActivity(intent);
9. ACTION_DATA_ROAMING_SETTINGS : // 跳转到移动网络设置界面
Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
startActivity(intent);
10. ACTION_DATE_SETTINGS : // 跳转日期时间设置界面
Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
startActivity(intent);
11. ACTION_DEVICE_INFO_SETTINGS : // 跳转手机状态界面
Intent intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);
startActivity(intent);
12. ACTION_DISPLAY_SETTINGS : // 跳转手机显示界面
Intent intent = new Intent(Settings.ACTION_DISPLAY_SETTINGS);
startActivity(intent);
13. ACTION_DREAM_SETTINGS 【API 18及以上 没测试】
Intent intent = new Intent(Settings.ACTION_DREAM_SETTINGS);
startActivity(intent);
14. ACTION_INPUT_METHOD_SETTINGS : // 跳转语言和输入设备
Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
startActivity(intent);
15. ACTION_INPUT_METHOD_SUBTYPE_SETTINGS 【API 11及以上】 // 跳转 语言选择界面 【多国语言选择】
Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
startActivity(intent);
16. ACTION_INTERNAL_STORAGE_SETTINGS // 跳转存储设置界面【内部存储】
Intent intent = new Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
startActivity(intent);
或者:
ACTION_MEMORY_CARD_SETTINGS : // 跳转 存储设置 【记忆卡存储】
Intent intent = new Intent(Settings.ACTION_MEMORY_CARD_SETTINGS);
startActivity(intent);
17. ACTION_LOCALE_SETTINGS : // 跳转语言选择界面【仅有English 和 中文两种选择】
Intent intent = new Intent(Settings.ACTION_LOCALE_SETTINGS);
startActivity(intent);
18. ACTION_LOCATION_SOURCE_SETTINGS : // 跳转位置服务界面【管理已安装的应用程序。】
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
19. ACTION_NETWORK_OPERATOR_SETTINGS : // 跳转到 显示设置选择网络运营商。
Intent intent = new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS);
startActivity(intent);
20. ACTION_NFCSHARING_SETTINGS : // 显示NFC共享设置。 【API 14及以上】
Intent intent = new Intent(Settings.ACTION_NFCSHARING_SETTINGS);
startActivity(intent);
21. ACTION_NFC_SETTINGS :// 显示NFC设置。这显示了用户界面,允许NFC打开或关闭。 【API 16及以上】
Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS);
startActivity(intent);
22. ACTION_PRIVACY_SETTINGS : // 跳转到备份和重置界面
Intent intent = new Intent(Settings.ACTION_PRIVACY_SETTINGS);
startActivity(intent);
23. ACTION_QUICK_LAUNCH_SETTINGS : // 跳转快速启动设置界面
Intent intent = new Intent(Settings.ACTION_QUICK_LAUNCH_SETTINGS);
startActivity(intent);
25. ACTION_SECURITY_SETTINGS : // 跳转到安全设置界面
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivity(intent);
28. ACTION_SYNC_SETTINGS : // 跳转账户同步界面
Intent intent = new Intent(Settings.ACTION_SYNC_SETTINGS);
startActivity(intent);
30. ACTION_WIFI_IP_SETTINGS : // 跳转到IP设定界面
Intent intent = new Intent(Settings.ACTION_WIFI_IP_SETTINGS);
startActivity(intent);
31. ACTION_WIFI_SETTINGS : // 跳转Wifi列表设置
以上是关于Intent之跳转总结的主要内容,如果未能解决你的问题,请参考以下文章
framework7-vue 踩坑之跳转之后之前的页面没有被销毁