Chinaunix首页 | 论坛 | 博客
  • 博客访问: 840429
  • 博文数量: 182
  • 博客积分: 1992
  • 博客等级: 上尉
  • 技术积分: 1766
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-18 11:49
文章分类

全部博文(182)

文章存档

2019年(1)

2016年(5)

2015年(29)

2014年(38)

2013年(21)

2012年(36)

2011年(52)

我的朋友

分类: 嵌入式

2011-08-17 15:42:27

转:http://dev.10086.cn/cmdn/wiki/index.php?doc-view-3637.html


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

Java代码 复制代码
  1. < activity android:name=".PackageInstallerActivity">      
  2. < intent-filter>      
  3. < action android:name="android.intent.action.VIEW" />      
  4. < category android:name="android.intent.category.DEFAULT" />      
  5. < data android:scheme="content" />      
  6. < data android:scheme="file" />      
  7. < data android:mimeType="application/vnd.android.package-archive" />      
  8. < /intent-filter>      
  9. < /activity>     
  10.     
  11. < activity android:name=".UninstallerActivity">      
  12. < intent-filter>      
  13. < action android:name="android.intent.action.VIEW" />      
  14. < action android:name="android.intent.action.DELETE" />      
  15. < category android:name="android.intent.category.DEFAULT" />      
  16. < data android:scheme="package" />      
  17. < /intent-filter>      
  18. < /activity>     

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

   

Java代码 复制代码
  1. String fileName = Environment.getExternalStorageDirectory() + "/myApp.apk";      
  2. Intent intent = new Intent(Intent.ACTION_VIEW);   
  3.   
  4. intent.setDataAndType(Uri.parse("file://" + filePath),"application/vnd.android.package-archive");   
  5. //或者   
  6. //intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");    
  7.   
  8. startActivity(intent);     

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

Java代码 复制代码
  1. Uri packageURI = Uri.parse("package:com.android.myapp");      
  2. Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);      
  3. startActivity(uninstallIntent);      

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

Java代码 复制代码
  1. int result = Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 0);      
  2. if (result == 0) {      
  3. // show some dialog here      
  4. // ...      
  5. // and may be show application settings dialog manually      
  6. Intent intent = new Intent();      
  7. intent.setAction(Settings.ACTION_APPLICATION_SETTINGS);      
  8. startActivity(intent);     
  9. }   
阅读(539) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~