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

1

2 Answers 2

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.

2
  • Is it possible to give the URL instead of downloading the apk and giving the local path Like I have a URL 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 Jan 5, 2013 at 5: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. Jan 5, 2013 at 5: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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.