Zack
Zack

Reputation: 73

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!

Upvotes: 6

Views: 4710

Answers (1)

Jorgesys
Jorgesys

Reputation: 126523

Use an Intent

Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse("http://dacp.jsharkey.org/TunesRemote-r2.apk"));
startActivity(intent);    

Upvotes: 3

Related Questions