2013-10-22 11 views
7

Android 4.2+のインテントを使用してapkをインストールするときにダウングレードを有効にすることはできますか?私はコマンドシェル経由でアプリケーションをインストールするとき(-dを使用して)adb install -r -d <link to apk>をインストールすることが可能であることを知ったので、Intent経由で何らかの形で可能であることを願っています。私はいくつかの旗や何かを探していたが、役に立たないものは見つけられなかった。非プラットフォーム(サードパーティ)のアプリケーションのためにことはできませんAndroid 4.2+のインテントを使用して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 .com/p/android/issues/detail?id = 62545 –

答えて

11

この

は、パッケージインストーラを開くために私の意図であるあなたが PackageManagerに直接インストール 要求をしなければなりません。

PackageManagerは、非パブリックAPIを持っていinstallPackage()(これを書いている時点では行2584):

可能なフラグの一つが INSTALL_ALLOW_DOWNGRADEある
/** 
* @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); 

/** 
* 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

質問には「あなたのgoogle」とタグ付けする必要があります... –

0

もう1つの解決策は、まずアプリをアンインストールしてからもう一度インストールすることです。別の方法を見つけることができませんでした。もし誰かがより良い解決策を見つけたら、私に教えてください:)

関連する問題