2

Is there way to be able to download and install another android app from a URL programmatically? I tried following

Intent promptInstall = new Intent(Intent.ACTION_VIEW);

    promptInstall.setDataAndType(Uri.fromFiledwfile), "application/vnd.android.package_archive");
    promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    startActivity(promptInstall);

but it gave me error

   java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.example.test/com.example.test.MainActivity}: 

android.content.ActivityNotFoundException: No Activity found to handle Intent { 

act=android.intent.action.VIEW dat=file:///mnt/sdcard/download/Demo.apk 

typ=application/vnd.android.package_archive flg=0x10000000 }

Am I missing some permissions? I tried giving

<uses-permission android:name="android.permission.INSTALL_PACKAGES"  />

but that doesn't let me compile in eclipse

Can someone please help and let me know if I am doing soemthing wrong

Thanks Monty

il_guru
  • 8,383
  • 2
  • 42
  • 51
user1950373
  • 181
  • 1
  • 1
  • 4
  • Remove that permission as it is not needed. Look at [this solution](http://stackoverflow.com/questions/4967669/android-install-apk-programmatically). – Oleg Vaskevich Jan 05 '13 at 04:51

2 Answers2

1

There's no way you can install an app without the user acknowledgement.

Once you have donwloaded the apk, you should use ACTION_INSTALL_PACKAGE instead of ACTION_VIEW

From the documentation:

Activity Action: Launch application installer.

Input: The data must be a content: or file: URI at which the application can be retrieved. As of JELLY_BEAN_MR1, you can also use "package:" to install an application for the current user that is already installed for another user. You can optionally supply EXTRA_INSTALLER_PACKAGE_NAME, EXTRA_NOT_UNKNOWN_SOURCE, EXTRA_ALLOW_REPLACE, and EXTRA_RETURN_RESULT.

Output: If EXTRA_RETURN_RESULT, returns whether the install succeeded.

Community
  • 1
  • 1
Robert Estivill
  • 12,369
  • 8
  • 43
  • 64
  • Is it possible to give the URL instead of downloading the apk and giving the local path Like I have a URL https://abc.example.com/filename.apk. I want to pass this URL to some API in android which can download and install the app. Can we do this? I am fine with showing the user that prompt before downloading/installing – user1950373 Jan 05 '13 at 05:18
  • From the docs: "The data must be a content: or file: URI", so no, you can not pass an http uri there. Take a look at the DownloadManager class that will download the file for you without having to deal with file integrity, retries, etc. You can then use the DownloadManager.query method to poll for the status, or register BroadcastListeners to listen for events. – Robert Estivill Jan 05 '13 at 05:26
0

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pass the url to downlad app));

    startActivity(browserIntent);

Rest provide the persimmion of internet and storage in manifest.

deepak825
  • 432
  • 2
  • 8