提交 077e24ec 编写于 作者: B Blankj

see 04/20 log

上级 99d2cf7a
......@@ -41,7 +41,7 @@
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.14-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.15-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
......@@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.14-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.15-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
......@@ -57,7 +57,7 @@ dependencies {
// LeakCanary
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version"
// implementation 'com.blankj:utilcode:1.13.14'
// implementation 'com.blankj:utilcode:1.13.15'
}
package com.blankj.androidutilcode;
import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.blankj.androidutilcode.base.BaseApplication;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.CrashUtils;
import com.blankj.utilcode.util.LogUtils;
import com.squareup.leakcanary.LeakCanary;
......@@ -75,23 +71,10 @@ public class UtilsApp extends BaseApplication {
@Override
public void onCrash(String crashInfo, Throwable e) {
LogUtils.e(crashInfo);
restartApp();
AppUtils.relaunchApp();
}
});
}
private void restartApp() {
Intent intent = new Intent();
intent.setClassName("com.blankj.androidutilcode", "com.blankj.androidutilcode.MainActivity");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent restartIntent = PendingIntent.getActivity(this, 0, intent, 0);
AlarmManager manager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
if (manager == null) return;
manager.set(AlarmManager.RTC, System.currentTimeMillis() + 1, restartIntent);
ActivityUtils.finishAllActivities();
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
}
......@@ -51,15 +51,10 @@ public class AppActivity extends BaseBackActivity {
findViewById(R.id.btn_uninstall_app).setOnClickListener(this);
findViewById(R.id.btn_uninstall_app_silent).setOnClickListener(this);
findViewById(R.id.btn_launch_app).setOnClickListener(this);
findViewById(R.id.btn_relaunch_app).setOnClickListener(this);
findViewById(R.id.btn_exit_app).setOnClickListener(this);
findViewById(R.id.btn_launch_app_details_settings).setOnClickListener(this);
TextView tvAboutApp = findViewById(R.id.tv_about_app);
// "pkg name: " + getPackageName() +
// "\napp name: " + getName() +
// "\napp path: " + getPackagePath() +
// "\napp v name: " + getVersionName() +
// "\napp v code: " + getVersionCode() +
// "\nis system: " + isSystem();
tvAboutApp.setText(new SpanUtils()
.appendLine("isAppRoot: " + AppUtils.isAppRoot())
.appendLine("isAppDebug: " + AppUtils.isAppDebug())
......@@ -136,6 +131,9 @@ public class AppActivity extends BaseBackActivity {
case R.id.btn_launch_app:
AppUtils.launchApp(this.getPackageName());
break;
case R.id.btn_relaunch_app:
AppUtils.relaunchApp();
break;
case R.id.btn_launch_app_details_settings:
AppUtils.launchAppDetailsSettings();
break;
......
......@@ -12,6 +12,8 @@ import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.DeviceUtils;
import com.blankj.utilcode.util.SpanUtils;
import java.util.Arrays;
/**
* <pre>
* author: Blankj
......@@ -53,7 +55,8 @@ public class DeviceActivity extends BaseBackActivity {
.appendLine("getAndroidID: " + DeviceUtils.getAndroidID())
.appendLine("getMacAddress: " + DeviceUtils.getMacAddress())
.appendLine("getManufacturer: " + DeviceUtils.getManufacturer())
.append("getModel: " + DeviceUtils.getModel())
.appendLine("getModel: " + DeviceUtils.getModel())
.append("getABIs: " + Arrays.asList(DeviceUtils.getABIs()))
.create()
);
}
......
......@@ -48,6 +48,13 @@
android:layout_height="wrap_content"
android:text="@string/app_launch" />
<Button
android:id="@+id/btn_relaunch_app"
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_relaunch" />
<Button
android:id="@+id/btn_launch_app_details_settings"
style="@style/WideBtnStyle"
......
......@@ -66,6 +66,7 @@
<string name="uninstall_successfully">Uninstall successfully</string>
<string name="uninstall_unsuccessfully">Uninstall unsuccessfully</string>
<string name="app_launch">Launch App</string>
<string name="app_relaunch">Relaunch App</string>
<string name="app_launch_details_settings">Launch App Details Settings</string>
<string name="app_exit">Exit App</string>
......
......@@ -33,8 +33,8 @@ ext {
min_sdk_version = 14
target_sdk_version = 27
version_code = 1_013_014
version_name = '1.13.14'// E.g 1.9.72 => 1,009,072
version_code = 1_013_015
version_name = '1.13.15'// E.g 1.9.72 => 1,009,072
// App dependencies
support_version = '27.1.0'
......
* 18/04/21 新增 AppUtils#relaunchApp、DeviceUtils#getABIs,发布 1.13.15 版本
* 18/04/20 新增 BarUtils#setNavBarColor、BarUtils#getNavBarColor
* 18/04/19 新增 Process#isMainProcess、Process#getCurrentProcessName,发布 1.13.14 版本
* 18/04/18 修复 LogUtils 头部空指针异常,SPUtils、CacheUtils 存储空值异常,发布 1.13.13 版本
......
......@@ -2,7 +2,7 @@
Gradle:
```groovy
implementation 'com.blankj:utilcode:1.13.14'
implementation 'com.blankj:utilcode:1.13.15'
```
......@@ -54,6 +54,7 @@ isAppDebug : 判断 App 是否是 Debug 版本
isAppSystem : 判断 App 是否是系统应用
isAppForeground : 判断 App 是否处于前台
launchApp : 打开 App
relaunchApp : 重启 App
launchAppDetailsSettings: 打开 App 具体设置
exitApp : 关闭应用
getAppIcon : 获取 App 图标
......@@ -161,6 +162,7 @@ getAndroidID : 获取设备 AndroidID
getMacAddress : 获取设备 MAC 地址
getManufacturer : 获取设备厂商
getModel : 获取设备型号
getABIs : 获取设备 ABIs
shutdown : 关机
reboot : 重启
reboot2Recovery : 重启到 recovery
......
......@@ -2,7 +2,7 @@
Gradle:
```groovy
implementation 'com.blankj:utilcode:1.13.14'
implementation 'com.blankj:utilcode:1.13.15'
```
......@@ -54,6 +54,7 @@ isAppDebug
isAppSystem
isAppForeground
launchApp
relaunchApp
launchAppDetailsSettings
exitApp
getAppIcon
......@@ -161,6 +162,7 @@ getAndroidID
getMacAddress
getManufacturer
getModel
getABIs
shutdown
reboot
reboot2Recovery
......
......@@ -2,6 +2,7 @@ package com.blankj.utilcode.util;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
......@@ -370,6 +371,19 @@ public final class AppUtils {
activity.startActivityForResult(IntentUtils.getLaunchAppIntent(packageName), requestCode);
}
/**
* Relaunch the application.
*/
public static void relaunchApp() {
PackageManager packageManager = Utils.getApp().getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(Utils.getApp().getPackageName());
if (intent == null) return;
ComponentName componentName = intent.getComponent();
Intent mainIntent = Intent.makeRestartActivityTask(componentName);
Utils.getApp().startActivity(mainIntent);
System.exit(0);
}
/**
* Launch the application's details settings.
*/
......
......@@ -9,6 +9,7 @@ import android.os.Build;
import android.os.PowerManager;
import android.provider.Settings;
import android.support.annotation.RequiresPermission;
import android.text.TextUtils;
import java.io.File;
import java.net.InetAddress;
......@@ -233,6 +234,23 @@ public final class DeviceUtils {
return model;
}
/**
* Return an ordered list of ABIs supported by this device. The most preferred ABI is the first
* element in the list.
*
* @return an ordered list of ABIs supported by this device
*/
public static String[] getABIs() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return Build.SUPPORTED_ABIS;
} else {
if (!TextUtils.isEmpty(Build.CPU_ABI2)) {
return new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
return new String[]{Build.CPU_ABI};
}
}
/**
* Shutdown the device
* <p>Requires root permission
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册