Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 568
Binh Nguyen Avatar asked Jun 20 '12 09:06

Binh Nguyen


People also ask

Can we download file in WebView?

Application Xamarin Forms Android. The application has a WebView element that displays different sites. On these sites, it is possible to download files. But the file cannot be downloaded via WebView.

What is WebView APK?

Android WebView is a pre-installed system component from Google that allows Android apps to display web content. Updated on. Nov 14, 2022. Tools.


1 Answers

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)

like image 51
RaB Avatar answered Sep 17 '22 17:09

RaB