安装和卸载Android程序

文章转自:http://blog.youkuaiyun.com/fenghome/archive/2010/06/16/5673757.aspx

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

  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卡安装一个程序:

  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安装卸载程序的操作中要想卸载一个程序:

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

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

  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. }

<wbr style="line-height:25px"></wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值