Android安装卸载程序具体操作方法解析

移动开发 Android
Android安装卸载程序在实际应用中是一个比较基本的操作。作为初学者来说需要牢固掌握这一应用技巧,以方便我们的使用。

对于编程爱好者们来说,Android手机操作系统是一款非常实用的系统。他们可以进行各种Android应用程序的开发来满足自的应用需求。在这里我们就先来为大家讲解一下有关Android安装卸载程序的具体操作步骤。

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

< 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> 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

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

String fileName = Environment.getExternalStorageDirectory() 
+ "/myApp.apk";   
Intent intent = new Intent(Intent.ACTION_VIEW);    intent.setDataAndType(Uri.fromFile(new File(fileName)), 
"application/vnd.android.package-archive");   
startActivity(intent);  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

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

Uri packageURI = Uri.parse("package:com.android.myapp");   
Intent uninstallIntent = new Intent
(Intent.ACTION_DELETE, packageURI);   
startActivity(uninstallIntent);  
  • 1.
  • 2.
  • 3.
  • 4.

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

int result = Settings.Secure.getInt(getContentResolver(),
 Settings.Secure.INSTALL_NON_MARKET_APPS, 0);   
if (result == 0) {    // show some dialog here    // ...    // and may be show application settings dialog manually    Intent intent = new Intent();    intent.setAction(Settings.ACTION_APPLICATION_SETTINGS);    startActivity(intent);   
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

Android安装卸载程序的具体实现方法就为大家介绍到这里。

【编辑推荐】

  1. Android Jni代码示例讲解 
  2. Android单元测试源码解读 
  3. Android判断网络状态方法详解 
  4. Android程序架构基本内容概述 
  5. Android调用平台功能具体技巧分享 
责任编辑:曹凯 来源: javaeye.com
相关推荐

2010-01-27 18:00:57

Android开机自启

2009-12-30 16:48:52

Silverlight

2010-02-02 13:57:31

C++解析#pragm

2010-02-02 17:13:35

C++ Endian

2010-04-02 08:42:32

Oracle 游标

2010-02-03 13:26:53

C++计时

2010-03-05 15:27:06

Python文件路径

2010-04-13 17:00:27

Oracle NLS_

2010-01-07 15:37:35

VB.NET ForNext循环

2010-02-02 16:23:46

C++实现WPF动画

2010-03-19 14:19:58

Python正则表达式

2010-03-05 17:06:26

Python显示UTF

2009-12-10 13:35:25

Linux操作系统

2009-12-30 15:47:40

Silverlight

2011-03-17 09:06:58

iptables映射端口

2009-09-10 14:49:00

2009-08-31 13:32:38

C#创建XML文件

2010-05-14 14:46:38

MySQL手动安装

2010-01-05 16:02:36

Ubuntu Git

2009-12-31 15:36:13

SilverLight
点赞
收藏

51CTO技术栈公众号