Android安装和卸载程序
16lz
2021-01-23
Android软件安装器Install
http://houjunli001.javaeye.com/blog/617405
在Android安装卸载程序的源码中我们知道:
[java]view plaincopy- <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]view plaincopy- 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]view plaincopy
- UripackageURI=Uri.parse("package:com.android.myapp");
- IntentuninstallIntent=newIntent(Intent.ACTION_DELETE,packageURI);
- startActivity(uninstallIntent);
默认是不支持安装非市场程序的 因此判断一下
[java]view plaincopy- 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);
- }
原文地址:点击打开链接
更多相关文章
- Android重启应用程序 && 不重启应用不改变系统语言改变 Android
- 【Android Developer】2.Android的第一个Helloworld程序
- Android:保护自己开发的Android应用程序
- 关于 Android 程序员最近的状况
- 第三部分:Android 应用程序接口指南---第一节:应用程序组件---第六
- Android应用程序的类型
- 自定义Android应用程序标题条