こんにちは、アプリを作成しましたが、壁にぶつかりました。Firefox や Chrome などのデスクトップ ブラウザを使用して Web サイトにアクセスし、ダウンロード リンクをクリックすると、ファイルのダウンロードが開始されますが、Android アプリで同じページを開いて WebView を使用してページを表示し、ダウンロード リンクをクリックしても何も起こりません。まったく、そのリンクをどうするか分からないように、ただそこに座っているだけです。あなたが私を助けてくれれば、それは大きな助けになり、私を再び軌道に乗せることができます.
これは、私のサイトで pdf ファイルに使用するダウンロード リンクです。
<img src="images/Art1.jpg" width="80" height="166" /><a href="m2.pdf">Download</a>
これは、私の Android アプリの main.xml ファイルです。
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
誰かが私を正しい道に導くのを手伝ってくれるなら、私は最も感謝しています。
package com.jeffonlinelibrary;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebPageLoader extends Activity
{
final Activity activity = this;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
// Handle the error
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
// handle download, here we use brower to download, also you can try other approach.
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
webView.loadUrl("http://jeffonlinelibrary.comuv.com/jeffOnlinelibraryApp");
}
}