|
@@ -7,6 +7,8 @@ import android.content.Intent;
|
|
|
import android.content.pm.ApplicationInfo;
|
|
import android.content.pm.ApplicationInfo;
|
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
|
|
|
+import android.provider.Settings;
|
|
|
|
|
+import android.text.TextUtils;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
@@ -81,21 +83,70 @@ public class NotificationsUtils {
|
|
|
*/
|
|
*/
|
|
|
public static void goToNotificationSetting(Context context) {
|
|
public static void goToNotificationSetting(Context context) {
|
|
|
Intent intent = new Intent();
|
|
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) {
|
|
|
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && TextUtils.equals(android.os.Build.BRAND, "360")){// 360 8.1.0 不能跳转成功,直接跳转应用详情设置界面
|
|
|
|
|
+ intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
|
|
+ intent.setData(Uri.fromParts("package", context.getPackageName(), null));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // android 8.0引导
|
|
|
|
|
+ intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
|
|
|
|
|
+ intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
// android 5.0-7.0
|
|
// android 5.0-7.0
|
|
|
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
|
|
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
|
|
|
intent.putExtra("app_package", context.getPackageName());
|
|
intent.putExtra("app_package", context.getPackageName());
|
|
|
intent.putExtra("app_uid", context.getApplicationInfo().uid);
|
|
intent.putExtra("app_uid", context.getApplicationInfo().uid);
|
|
|
} else {
|
|
} else {
|
|
|
// 其他
|
|
// 其他
|
|
|
- intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
|
|
|
|
|
|
|
+ intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
intent.setData(Uri.fromParts("package", context.getPackageName(), null));
|
|
intent.setData(Uri.fromParts("package", context.getPackageName(), null));
|
|
|
}
|
|
}
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
context.startActivity(intent);
|
|
context.startActivity(intent);
|
|
|
}
|
|
}
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 打开允许通知的设置页
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void goToNotificationSetting0(Context context) {
|
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
|
+ // android 8.0引导
|
|
|
|
|
+ intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
|
|
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
+ context.startActivity(intent);
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 打开允许通知的设置页
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void goToNotificationSetting1(Context context) {
|
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
|
+ // android 8.0引导
|
|
|
|
|
+ intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
|
|
|
|
|
+ intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName());
|
|
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
+ context.startActivity(intent);
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 打开允许通知的设置页
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void goToNotificationSetting2(Context context) {
|
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
|
+ // 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);
|
|
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
+ context.startActivity(intent);
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 打开允许通知的设置页
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void goToNotificationSetting3(Context context) {
|
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
|
+ // 其他
|
|
|
|
|
+ intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
|
|
+ intent.setData(Uri.fromParts("package", context.getPackageName(), null));
|
|
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
+ context.startActivity(intent);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|