6

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!

Zack
  • 73
  • 2
  • 4

1 Answers1

3

Use an Intent

Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse("http://dacp.jsharkey.org/TunesRemote-r2.apk"));
startActivity(intent);    
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • Awesome thank you! It worked! I've also found another way using using URLConnection, BufferedInputStream, and BufferedOutputStream. Could you tell me the difference between using this method I found and the one you suggested? Thanks again! – Zack Jul 09 '10 at 18:11