Android安装卸载程序解析
16lz
2021-01-23
在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>
< activity android:name=".PackageInstallerActivity"> < intent-filter> < action android:name="android.intent.action.VIEW" /> < category android:name="android.intent.category.DEFAULT" /> < data android:scheme="content" /> < data android:scheme="file" /> < data android:mimeType="application/vnd.android.package-archive" /> < /intent-filter> < /activity> < activity android:name=".UninstallerActivity"> < intent-filter> < action android:name="android.intent.action.VIEW" /> < action android:name="android.intent.action.DELETE" /> < category android:name="android.intent.category.DEFAULT" /> < data android: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);
String fileName = Environment.getExternalStorageDirectory() + "/myApp.apk"; Intent intent = new Intent(Intent.ACTION_VIEW);intent.setDataAndType(Uri.parse("file://" + filePath),"application/vnd.android.package-archive");//或者//intent.setDataAndType(Uri.fromFile(new File(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);
Uri packageURI = Uri.parse("package:com.android.myapp"); Intent uninstallIntent = new Intent(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);
- }
- 转载:http://panxq0809.iteye.com/blog/668772
更多相关文章
- Android下使用Properties文件保存程序设置
- Android通过WebView调用 JS 代码
- android 设备开发 让应用程序出现在模拟器启动列表中
- Android应用程序键盘(Keyboard)消息处理机制分析(22)
- Android下为自己定义WifiManager类wifi模块代码
- 如何提高android代码质量
- 安卓基础学习 Day01 |第一个安卓应用程序:Hello Word!
- Android日志系统Logcat源代码简要分析