Commit b7d1c017665feed291b778056f0988ad89ab15af
1 parent
99f1762f
1 修改白名单及通知权限检查逻辑
Showing
6 changed files
with
35 additions
and
26 deletions
config.gradle
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/ui/activity/CollRunRaceDetailActivity.java
| ... | ... | @@ -71,7 +71,7 @@ public class CollRunRaceDetailActivity extends QMUIFragmentActivity { |
| 71 | 71 | super.onResume(); |
| 72 | 72 | boolean isSet = CheckUtil.isIgnoringBatteryOptimizationss(this); |
| 73 | 73 | if (!isSet) { |
| 74 | - isSet = CheckUtil.isIgnoringBatteryOptimizationss(this); | |
| 74 | + CheckUtil.toSetIgnore(this); | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/ui/activity/StartCollectTraceActivity.java
| ... | ... | @@ -75,11 +75,13 @@ public class StartCollectTraceActivity extends QMUIFragmentActivity { |
| 75 | 75 | } else { |
| 76 | 76 | boolean isSetBattery = CheckUtil.isIgnoringBatteryOptimizationss(StartCollectTraceActivity.this); |
| 77 | 77 | if (!isSetBattery) { |
| 78 | - isSetBattery = CheckUtil.isIgnoringBatteryOptimizationss(StartCollectTraceActivity.this); | |
| 78 | + CheckUtil.toSetIgnore(this); | |
| 79 | 79 | } else { |
| 80 | 80 | getPermissionsWithTip(); |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | + } else { | |
| 84 | + NotificationUtil.goToSettingNo(this); | |
| 83 | 85 | } |
| 84 | 86 | } |
| 85 | 87 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/activity/RunRaceDetailActivity.java
| ... | ... | @@ -142,11 +142,13 @@ public class RunRaceDetailActivity extends QMUIFragmentActivity { |
| 142 | 142 | } else { |
| 143 | 143 | boolean isSetBattery = CheckUtil.isIgnoringBatteryOptimizationss(RunRaceDetailActivity.this); |
| 144 | 144 | if (!isSetBattery) { |
| 145 | - isSetBattery = CheckUtil.isIgnoringBatteryOptimizationss(RunRaceDetailActivity.this); | |
| 145 | + CheckUtil.toSetIgnore(this); | |
| 146 | 146 | } else { |
| 147 | 147 | getPermissionsWithTip(); |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | + }else { | |
| 151 | + NotificationUtil.goToSettingNo(this); | |
| 150 | 152 | } |
| 151 | 153 | |
| 152 | 154 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/CheckUtil.java
| ... | ... | @@ -7,6 +7,7 @@ import android.content.pm.PackageManager; |
| 7 | 7 | import android.net.Uri; |
| 8 | 8 | import android.os.PowerManager; |
| 9 | 9 | import android.provider.Settings; |
| 10 | +import android.widget.Toast; | |
| 10 | 11 | |
| 11 | 12 | import com.cnlive.libs.base.util.AlertUtil; |
| 12 | 13 | |
| ... | ... | @@ -21,27 +22,34 @@ public class CheckUtil { |
| 21 | 22 | * @return |
| 22 | 23 | */ |
| 23 | 24 | public static boolean isIgnoringBatteryOptimizationss(Activity context) { |
| 24 | - String carrier = android.os.Build.MANUFACTURER; | |
| 25 | - if (!"smartisan".equals(carrier)) { | |
| 26 | - PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE); | |
| 27 | - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { | |
| 28 | - boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(context.getPackageName()); | |
| 29 | - if (!hasIgnored) { | |
| 30 | - Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); | |
| 31 | - intent.setData(Uri.parse("package:" + context.getPackageName())); | |
| 32 | - PackageManager pm = context.getPackageManager(); | |
| 33 | - if (intent.resolveActivity(pm) != null) { | |
| 34 | - context.startActivity(intent); | |
| 35 | - } | |
| 36 | - AlertUtil.showDeftToast(context, "请选择允许加入电池优化白名单,否则将会影响您的正常使用!"); | |
| 37 | - return false; | |
| 38 | - } else { | |
| 39 | - return true; | |
| 25 | + try { | |
| 26 | + String carrier = android.os.Build.MANUFACTURER; | |
| 27 | + if (!"smartisan".equals(carrier)) { | |
| 28 | + PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE); | |
| 29 | + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { | |
| 30 | + boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(context.getPackageName()); | |
| 31 | + return hasIgnored; | |
| 40 | 32 | } |
| 33 | + } else { | |
| 34 | + return true; | |
| 41 | 35 | } |
| 42 | - } else { | |
| 36 | + return false; | |
| 37 | + } catch (Exception e) { | |
| 43 | 38 | return true; |
| 44 | 39 | } |
| 45 | - return false; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public static void toSetIgnore(Activity context) { | |
| 43 | + try { | |
| 44 | + Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); | |
| 45 | + intent.setData(Uri.parse("package:" + context.getPackageName())); | |
| 46 | + PackageManager pm = context.getPackageManager(); | |
| 47 | + if (intent.resolveActivity(pm) != null) { | |
| 48 | + context.startActivity(intent); | |
| 49 | + AlertUtil.showDeftToast(context, "请选择允许加入电池优化白名单,否则将会影响您的正常使用!"); | |
| 50 | + | |
| 51 | + } | |
| 52 | + } catch (Exception e) { | |
| 53 | + } | |
| 46 | 54 | } |
| 47 | 55 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/NotificationUtil.java
| ... | ... | @@ -20,13 +20,10 @@ public class NotificationUtil { |
| 20 | 20 | //监测通知权限是否打开 |
| 21 | 21 | notificationManagerCompat = NotificationManagerCompat.from(activity); |
| 22 | 22 | isOpen = notificationManagerCompat.areNotificationsEnabled(); |
| 23 | - if (!isOpen) { | |
| 24 | - goToSettingNo(activity); | |
| 25 | - } | |
| 26 | 23 | return isOpen; |
| 27 | 24 | } |
| 28 | 25 | |
| 29 | - private static void goToSettingNo(Activity activity) { | |
| 26 | + public static void goToSettingNo(Activity activity) { | |
| 30 | 27 | Toast.makeText(activity, "您尚未开启通知权限,无法进行计步", Toast.LENGTH_LONG).show(); |
| 31 | 28 | Intent intent1 = new Intent(); |
| 32 | 29 | try { | ... | ... |