2013-10-22 26 views
7

使用Android 4.2+ intent安裝apk時,是否可以啓用降級?我發現當通過命令shell(使用-d)adb install -r -d <link to apk>安裝應用程序時,有可能通過Intent來實現某種程度的可能。我正在尋找一些國旗或其他東西,但我沒有找到有用的東西。在Android 4.2+使用intent安裝apk時啓用降級

這是我的意圖打開包裝安裝:

Intent intent = new Intent(Intent.ACTION_VIEW); 
Uri applicatonFileUri = Uri.fromFile(applicationFile); 
intent.setDataAndType(applicatonFileUri, PACKAGE_TYPE); 
startActivity(intent); 
+2

如果這讓您的企業客戶感到不安,就像我的企業客戶一樣,請在此列出問題:https://code.google .com/p/android/issues/detail?id = 62545 –

回答

11

這是不可能的非平臺(第三方)的應用程序:你必須安裝要求直接PackageManager

PackageManager具有非公開的API,installPackage()(截至記者發稿行2584):

/** 
* @hide 
* 
* Install a package. Since this may take a little while, the result will 
* be posted back to the given observer. An installation will fail if the calling context 
* lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the 
* package named in the package file's manifest is already installed, or if there's no space 
* available on the device. 
* 
* @param packageURI The location of the package file to install. This can be a 'file:' or a 
* 'content:' URI. 
* @param observer An observer callback to get notified when the package installation is 
* complete. {@link IPackageInstallObserver#packageInstalled(String, int)} will be 
* called when that happens. observer may be null to indicate that no callback is desired. 
* @param flags - possible values: {@link #INSTALL_FORWARD_LOCK}, 
* {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}. 
* @param installerPackageName Optional package name of the application that is performing the 
* installation. This identifies which market the package came from. 
*/ 
public abstract void installPackage(
     Uri packageURI, IPackageInstallObserver observer, int flags, 
     String installerPackageName); 

其中可能的標誌之一是INSTALL_ALLOW_DOWNGRADE

/** 
* Flag parameter for {@link #installPackage} to indicate that it is okay 
* to install an update to an app where the newly installed app has a lower 
* version code than the currently installed app. 
* 
* @hide 
*/ 
public static final int INSTALL_ALLOW_DOWNGRADE = 0x00000080; 

所有這些API是隱性的,第三方應用無法訪問。現在,您可以嘗試反思,但我非常肯定平臺會限制對它們的訪問。

+9

問題應該被標記爲'該死的谷歌'... –

0

另一個可能的解決方案是讓另一個應用程序先卸載您的應用程序,然後再次安裝它。我無法找到另一種方式,如果有人找到更好的解決方案,請讓我知道:)