|
@@ -148,18 +148,18 @@ public class PackageManagerCompat {
|
|
|
* 重启
|
|
|
* @param context 应用上下文
|
|
|
*/
|
|
|
-// public static void restartApp(Context context) {
|
|
|
-// Log.i(TAG, "restartApp: 应用程序重启中! 日期=====>" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
-// Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
|
-// PendingIntent restartIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
|
|
-// AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
|
-//
|
|
|
-// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {// 6.0及以上
|
|
|
-// mgr.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, restartIntent);
|
|
|
-//
|
|
|
-// } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {// 4.4及以上
|
|
|
-// mgr.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, restartIntent);
|
|
|
-// }
|
|
|
-// Log.i(TAG, "restartApp: 应用程序重启完成! 日期=====>" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
-// }
|
|
|
+ public static void restartApp(Context context) {
|
|
|
+ Log.i(TAG, "restartApp: 应用程序重启中! 日期=====>" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
+ Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
|
+ PendingIntent restartIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
|
|
+ AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
|
+
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {// 6.0及以上
|
|
|
+ mgr.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, restartIntent);
|
|
|
+
|
|
|
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {// 4.4及以上
|
|
|
+ mgr.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, restartIntent);
|
|
|
+ }
|
|
|
+ Log.i(TAG, "restartApp: 应用程序重启完成! 日期=====>" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
+ }
|
|
|
}
|