Android软件安装器Install

http://houjunli001.javaeye.com/blog/617405

在Android安装卸载程序的源码中我们知道:

[java]view plaincopy
  1. <activityandroid:name=".PackageInstallerActivity">
  2. <intent-filter>
  3. <actionandroid:name="android.intent.action.VIEW"/>
  4. <categoryandroid:name="android.intent.category.DEFAULT"/>
  5. <dataandroid:scheme="content"/>
  6. <dataandroid:scheme="file"/>
  7. <dataandroid:mimeType="application/vnd.android.package-archive"/>
  8. </intent-filter>
  9. </activity>
  10. <activityandroid:name=".UninstallerActivity">
  11. <intent-filter>
  12. <actionandroid:name="android.intent.action.VIEW"/>
  13. <actionandroid:name="android.intent.action.DELETE"/>
  14. <categoryandroid:name="android.intent.category.DEFAULT"/>
  15. <dataandroid:scheme="package"/>
  16. </intent-filter>
  17. </activity>

因为根据里面的权限我们可以 从sd卡安装一个程序:

[java]view plaincopy
  1. StringfileName=Environment.getExternalStorageDirectory()+"/myApp.apk";
  2. Intentintent=newIntent(Intent.ACTION_VIEW);
  3. intent.setDataAndType(Uri.parse("file://"+filePath),"application/vnd.android.package-archive");
  4. //或者
  5. //intent.setDataAndType(Uri.fromFile(newFile(fileName)),"application/vnd.android.package-archive");
  6. startActivity(intent);

Android安装卸载程序的操作中要想卸载一个程序:

[java]view plaincopy
  1. UripackageURI=Uri.parse("package:com.android.myapp");
  2. IntentuninstallIntent=newIntent(Intent.ACTION_DELETE,packageURI);
  3. startActivity(uninstallIntent);

默认是不支持安装非市场程序的 因此判断一下

[java]view plaincopy
  1. intresult=Settings.Secure.getInt(getContentResolver(),Settings.Secure.INSTALL_NON_MARKET_APPS,0);
  2. if(result==0){
  3. //showsomedialoghere
  4. //...
  5. //andmaybeshowapplicationsettingsdialogmanually
  6. Intentintent=newIntent();
  7. intent.setAction(Settings.ACTION_APPLICATION_SETTINGS);
  8. startActivity(intent);
  9. }

原文地址:点击打开链接

更多相关文章

  1. Android重启应用程序 && 不重启应用不改变系统语言改变 Android
  2. 【Android Developer】2.Android的第一个Helloworld程序
  3. Android:保护自己开发的Android应用程序
  4. 关于 Android 程序员最近的状况
  5. 第三部分:Android 应用程序接口指南---第一节:应用程序组件---第六
  6. Android应用程序的类型
  7. 自定义Android应用程序标题条

随机推荐

  1. 【Android(安卓)总结】缩写
  2. 14 Android(安卓)android 按钮效果的两种
  3. [置顶] androidの下拉菜单Spinner使用
  4. Android(安卓)实现部分文字高亮的三种方
  5. Android中如何判断是否联网
  6. 【Android-File】Android文件的读写
  7. Android(安卓)pthread mutex 实现分析
  8. android 渐变背景
  9. Android(安卓)Error:AAPT: error: resourc
  10. android中的Touch触摸事件传递机制