代码安装apk
- Intent i = new Intent(Intent.ACTION_VIEW);
- String filePath = "/sdcard/XXX.apk";
- i.setDataAndType(Uri.parse("file://" + filePath),"application/vnd.android.package-archive");
- context.startActivity(i);
复制代码
程序卸载
- Intent intent = new Intent(Intent.ACTION_DELETE, uri);
- intent.startActivity();
复制代码
监听是否卸载成功
- DeleteReceiver mDeleteReceiver = new DeleteReceiver();//自定义的广播接收类,接收到结果后的操作
- IntentFilter filter = new IntentFilter(
- Intent.ACTION_PACKAGE_DATA_CLEARED);
- filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
- filter.addDataScheme("package");
- registerReceiver(mDeleteReceiver, filter); //注册广播和过滤
- Intent undeleteIntent = new Intent(Intent.ACTION_DELETE, packageURI);
- startActivity(undeleteIntent);
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-07 08:32:14