在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(安卓)framework完整源码下载
  2. Android通过WebView调用 JS 代码
  3. android判断APP是否已经安装
  4. android 常用intent
  5. Android下为自己定义WifiManager类wifi模块代码
  6. 去掉android的屏幕上的title bar
  7. Android(安卓)HAL 开发 (1)
  8. Android(安卓)Camera Parameters
  9. Ubuntu安装Android(安卓)Studio

随机推荐

  1. listview check
  2. OpenCV在Windows、Linux、Android、iOS上
  3. eglCreateContext
  4. android 编写简易视频播放器
  5. Android---32---RatingBar
  6. Android(安卓)的通话代码练习
  7. Android(安卓)围绕中心旋转一个ImageView
  8. android 天气预报 界面
  9. Android文件简单读写操作
  10. 你追我赶进度条