Android安装、卸载、打开代码

安装:

String str = "/CanavaCancel.apk";
String fileName = Environment.getExternalStorageDirectory() + str;
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);

卸载:

Uri packageURI = Uri.parse("package:com.demo.CanavaCancel");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);

打开:

String str = "/CanavaCancel.apk";
String file = Environment.getExternalStorageDirectory() + str;
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
startActivity(intent);

你可能感兴趣的:(Android,Android安装,卸载,打开,android,android,studio,安卓)