2016-04-20 14 views
0
 Button btn = (Button) findViewById(R.id.Savenotes); 
    btn.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); 
      request.allowScanningByMediaScanner(); 
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION); 

      DownloadManager manager = (DownloadManager) getApplicationContext().getSystemService(Context.DOWNLOAD_SERVICE); 
      manager.enqueue(request); 
     } 

webviewにあるコンテンツをダウンロードしようとしています。ダウンロードマネージャを使用していますが、何も起こっていません。PDFや画像のようなWebビューのコンテンツをダウンロードするには?

答えて

0
webView.setDownloadListener(new DownloadListener() 
    { 
    public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) 
    { 
    //for downloading directly through download manager 
    Request request = new Request(Uri.parse(url)); 
    request.allowScanningByMediaScanner(); 
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "download"); 
    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); 
    dm.enqueue(request); 
    } 
    }); 
+0

PDFのために私は= "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl最終文字列のURLを使用しています。ボタンを押しても何も起こっていない –

+0

あなたはwebviewの中のファイルをダウンロードしたいのですか?あなたはwebview –

+0

からbtnをクリックしてダウンロードしたいと言っています。私はメモリ内のファイルをダウンロードしたいです。 –

0
webView.setDownloadListener(new DownloadListener() { 
public void onDownloadStart(String url, String userAgent, 
      String contentDisposition, String mimetype, 
      long contentLength) { 
    Intent i = new Intent(Intent.ACTION_VIEW); 
    i.setData(Uri.parse(url)); 
    startActivity(i); 
}}); 
+0

@ Bhavin Jadavさんは働いていませんでした –

関連する問題