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

Java代码 复制代码
  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>
< 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代码 复制代码
  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);
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代码 复制代码
  1. UripackageURI=Uri.parse("package:com.android.myapp");
  2. IntentuninstallIntent=newIntent(Intent.ACTION_DELETE,packageURI);
  3. startActivity(uninstallIntent);
Uri packageURI = Uri.parse("package:com.android.myapp");   Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);   startActivity(uninstallIntent);  

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

Java代码 复制代码
  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. }
  10. 转载:http://panxq0809.iteye.com/blog/668772

更多相关文章

  1. Android下使用Properties文件保存程序设置
  2. Android通过WebView调用 JS 代码
  3. android 设备开发 让应用程序出现在模拟器启动列表中
  4. Android应用程序键盘(Keyboard)消息处理机制分析(22)
  5. Android下为自己定义WifiManager类wifi模块代码
  6. 如何提高android代码质量
  7. 安卓基础学习 Day01 |第一个安卓应用程序:Hello Word!
  8. Android日志系统Logcat源代码简要分析

随机推荐

  1. 关于相对布局RelativeLayout的各种属性
  2. [转]Android进程管理
  3. Android(安卓)多媒体扫描过程(Android(安
  4. [转]Android(安卓)EditView属性
  5. Android(安卓)Activity onNewIntent() 详
  6. Android(安卓)NDK编程浅入深出之--了解ND
  7. android adb命令 抓取系统各种 log
  8. Android实现九宫格
  9. Android之MotionLayout(四),用 MotionLay
  10. android studio ndk 开发以及问题