Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to imitate default browser to download .apk files from webview?

Can someone explain me how I would be able to imitate the default browser when trying to download .apk from the net?

So far I have this:

WebView webview;

@Override
public void onCreate(Bundle icicle)
        {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        webview = (WebView) findViewById(R.id.webview);
        webview.setWebViewClient(new HelloWebViewClient());
        WebSettings webSettings = webview.getSettings();
        webSettings.setSavePassword(false);
        webSettings.setSaveFormData(false);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(false);

        webview.setDownloadListener(new DownloadListener() {
            public void onDownloadStart(final String url, String userAgent,
            String contentDisposition, String mimetype,
            long contentLength) {
            Toast.makeText(testapp.this, url, Toast.LENGTH_LONG);
            }
            });

        webview.loadUrl("http://dacp.jsharkey.org/TunesRemote-r2.apk");       

        }

I've already added the permission to use the internet. Are there any other permissions that I need to add? Am I doing the DownloadListener incorrectly?

Thank you in advance!

like image 547
Zack Avatar asked Jul 07 '10 22:07

Zack


People also ask

Which browser does WebView use?

But a wide variety of other Android applications also use it to display web content that isn't a part of the app. The WebView app is based on Chromium, the same open source project that powers the Google Chrome web browser, but it doesn't include all the features present in the full version of Chrome.

What is alternative of WebView in android?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

What is Android WebView browser?

Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application.


1 Answers

Use an Intent

Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse("http://dacp.jsharkey.org/TunesRemote-r2.apk"));
startActivity(intent);    
like image 122
Jorgesys Avatar answered Nov 02 '22 15:11

Jorgesys