Android安装卸载程序具体操作方法解析
16lz
2021-12-04
在Android安装卸载程序的源码中我们知道:
Java代码- <activityandroid:name=".PackageInstallerActivity">
- <intent-filter>
- <actionandroid:name="android.intent.action.VIEW"/>
- <categoryandroid:name="android.intent.category.DEFAULT"/>
- <dataandroid:scheme="content"/>
- <dataandroid:scheme="file"/>
- <dataandroid:mimeType="application/vnd.android.package-archive"/>
- </intent-filter>
- </activity>
- <activityandroid:name=".UninstallerActivity">
- <intent-filter>
- <actionandroid:name="android.intent.action.VIEW"/>
- <actionandroid:name="android.intent.action.DELETE"/>
- <categoryandroid:name="android.intent.category.DEFAULT"/>
- <dataandroid:scheme="package"/>
- </intent-filter>
- </activity>
因为根据里面的权限我们可以 从sd卡安装一个程序:
Java代码
- StringfileName=Environment.getExternalStorageDirectory()+"/myApp.apk";
- Intentintent=newIntent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse("file://"+filePath),"application/vnd.android.package-archive");
- //或者
- //intent.setDataAndType(Uri.fromFile(newFile(fileName)),"application/vnd.android.package-archive");
- startActivity(intent);
Android安装卸载程序的操作中要想卸载一个程序;
Java代码- UripackageURI=Uri.parse("package:com.android.myapp");
- IntentuninstallIntent=newIntent(Intent.ACTION_DELETE,packageURI);
- startActivity(uninstallIntent);
默认是不支持安装非市场程序的 因此判断一下
Java代码- intresult=Settings.Secure.getInt(getContentResolver(),Settings.Secure.INSTALL_NON_MARKET_APPS,0);
- if(result==0){
- //showsomedialoghere
- //...
- //andmaybeshowapplicationsettingsdialogmanually
- Intentintent=newIntent();
- intent.setAction(Settings.ACTION_APPLICATION_SETTINGS);
- startActivity(intent);
- }
更多相关文章
- Pycharm安装PyQt5的详细教程
- Android代码混淆打包
- Android(安卓)新手摸石头过河
- Android(安卓)获取已经安装的程序
- android: 大量开源项目源代码分享
- 史上最全!最经典!最无私的Android资料(书籍+代码)分享-不要积分
- 用layer-list一次加载多个层次图片
- Android(安卓)利用canvas画各种图形(点、直线、弧、圆、椭圆、文
- 圆形button