2016-11-09 42 views
0

私はwebviewでフォームURLを開く必要があるアンドロイドアプリケーションを使用しています。私はwebviewでフォームを開くことができます、フォームと共に送信ボタンがあります。このボタンをクリックするとwebview内のファイルがダウンロードされますが、それは起こっていません。私はgoogle chromeのようなモバイルで普通のブラウザでファイルをダウンロードすることができます。私はどのように私のアプリケーションwebview内でファイルをダウンロードできますか?WebView内でファイルがダウンロードされない

答えて

0

私はあなたがしようとしているかわからないが、あなたはWebViewの

mWebView.setDownloadListener(new DownloadListener() {  

public void onDownloadStart(String url, String userAgent, 
            String contentDisposition, String mimetype, 
            long contentLength) { 
      DownloadManager.Request request = new DownloadManager.Request(
        Uri.parse(url)); 

      request.allowScanningByMediaScanner(); 
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! 
      request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Name of your downloadble file goes here, example: Mathematics II "); 
      DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); 
      dm.enqueue(request); 
      Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); //This is important! 
      intent.addCategory(Intent.CATEGORY_OPENABLE); //CATEGORY.OPENABLE 
      intent.setType("*/*");//any application,any extension 
      Toast.makeText(getApplicationContext(), "Downloading File", //To notify the Client that the file is being downloaded 
        Toast.LENGTH_LONG).show(); 

     } 
    }); 

内のファイルをダウンロードするには、このコードを使用することができますし、あなたのAndroidマニフェストファイルにこの権限を追加

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

願っています!

+0

ご回答いただきありがとうございますが、残念ながらそれが機能していません。通常のブラウザで同じURLを開いた場合、私のファイルがダウンロードされます。 – vickyVick

関連する問題