Binh Nguyen
Binh Nguyen

Reputation: 1313

Android - Download and Install apk file in Webview

I am trying to make a simple webview for my mobile website. There are app link .apk on that website and I need to detect when user click on those link. After clicking file will be downloaded to SD card, then form user to install if want to..

I have read many solutions but did not get working solution yet.

Now all good at step to detect the .apk file, but it seem open default browser for those download link in second then go off, and I don't know how to auto-form install after downloaded.

My Code that I used.

Upvotes: 7

Views: 7719

Answers (1)

RaB
RaB

Reputation: 1565

Typically the embedded webview wont have all the features that the normal browser has. Therefore, once you catch the click on the apk then you have to do one of the following

  1. Download the file via the Android DownloadManager (example here http://www.vogella.com/blog/2011/06/14/android-downloadmanager-example/)
  2. Download the file yourself via HttpUrlConnection

Once the download has completed, you can try and kick off the install via an Intent (most likely Intent.ACTION_VIEW) or install directly via PackageManager. See here install / uninstall APKs programmatically (PackageManager vs Intents)

Upvotes: 1

Related Questions