java中launch方法,Java AppUtils.launchApp方法代码示例

段干河
2023-12-01

import com.blankj.utilcode.util.AppUtils; //导入方法依赖的package包/类

@Override

public void onWidgetClick(View view) {

switch (view.getId()) {

case R.id.btn_install_app:

if (AppUtils.isInstallApp(Config.TEST_PKG)) {

ToastUtils.showShort(R.string.app_install_tips);

} else {

PermissionHelper.requestStorage(new PermissionHelper.OnPermissionGrantedListener() {

@Override

public void onPermissionGranted() {

AssertHelper.releaseInstallApk(new AssertHelper.OnReleasedListener() {

@Override

public void onReleased() {

AppUtils.installApp(

Config.TEST_APK_PATH,

"com.blankj.androidutilcode.provider"

);

}

});

}

});

}

break;

case R.id.btn_install_app_silent:

if (AppUtils.isInstallApp(Config.TEST_PKG)) {

ToastUtils.showShort(R.string.app_install_tips);

} else {

if (AppUtils.installAppSilent(Config.TEST_APK_PATH)) {

ToastUtils.showShort(R.string.install_successfully);

} else {

ToastUtils.showShort(R.string.install_unsuccessfully);

}

}

break;

case R.id.btn_uninstall_app:

if (AppUtils.isInstallApp(Config.TEST_PKG)) {

AppUtils.uninstallApp(Config.TEST_PKG);

} else {

ToastUtils.showShort(R.string.app_uninstall_tips);

}

break;

case R.id.btn_uninstall_app_silent:

if (AppUtils.isInstallApp(Config.TEST_PKG)) {

if (AppUtils.uninstallAppSilent(Config.TEST_PKG, false)) {

ToastUtils.showShort(R.string.uninstall_successfully);

} else {

ToastUtils.showShort(R.string.uninstall_unsuccessfully);

}

} else {

ToastUtils.showShort(R.string.app_uninstall_tips);

}

break;

case R.id.btn_launch_app:

AppUtils.launchApp(this.getPackageName());

break;

case R.id.btn_exit_app:

AppUtils.exitApp();

break;

case R.id.btn_get_app_details_settings:

AppUtils.getAppDetailsSettings();

break;

}

}

 类似资料: