Android 程序的安装、卸载和更新
1、?通过Intent机制,调出系统安装应用,重新安装应用的话,会保留原应用的数据。
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri, application/vnd.android.package-archive");
2、?直接调用安装接口。
?
Uri mPackageURI = Uri.fromFile(new File(Environment.getExternalStorageDirectory()+ apkName));
int installFlags = 0;
PackageManager pm =getPackageManager();
try
{
??? PackageInfo pi = pm.getPackageInfo(packageName,
?? ?PackageManager.GET_UNINSTALLED_PACKAGES);
??? if(pi != null)
??? {
??????? installFlags |= PackageManager.REPLACE_EXISTING_PACKAGE;
??? }
}
catch (NameNotFoundException e)
{}
PackageInstallObserver observer= new PackageInstallObserver();
3、?执行install命令。
4、?执行cp / adb push命令。
5、?通过第三方软件实现。
new Intent(Intent.ACTION_VIEW,Uri.parse("market://search?q=pname:your.app.id"));
1、?通过Intent机制,调出系统卸载应用。
Intent intent = new Intent(Intent.ACTION_DELETE);
2、?直接调用卸载接口。
?
PackageInstallObserver observer= new PackageInstallObserver();
3、?运行rm apk安装文件,由系统检测后调用卸载应用。
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.?????????}
public static final?String?INSTALL_NON_MARKET_APPS
Since:?API Level 3
Whether the packageinstaller should allow installation of apps downloaded from sources other thanthe Android Market (vending machine). 1 = allow installing from other sources 0= only allow installing from the Android Market。
?
下面是程序更新的几个步骤演示:

?
?
?
