Android Webview不下载PDF

时间:2017-04-14 19:26:30

标签: android pdf android-webview

我无法在我的应用中的网页浏览中下载PDF文件。

我已将webview放入我的Android应用程序并访问PDF链接。在iOS上,相同的设置下载PDF,但在Android中没有任何反应。我已在浏览器中测试了PDF链接以确保其有效。它也适用于iOS。

此外,webview将显示一个网页(如谷歌),但不会下载PDF。我在设备上安装了PDF阅读器。

我确保我的清单包含:uses-permission android:name =“android.permission.INTERNET”

我已经广泛搜索并看到其他人之前遇到过此问题,但解决方案似乎总是过于复杂或干扰(在SELinx中更改权限?)。这应该是一个简单回答的常见任务,所以我必须遗漏一些明显的东西。

我被困住了。任何帮助表示赞赏。

这是我的网络视图代码:

public class WebActivity extends MenuActivity {

public static final String TARGET_URL = "com.hawthornemackenzie.congressfoundationandroid.target_url";
private String mTargetURLString;
public WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);
    mTargetURLString = getIntent().getStringExtra(TARGET_URL);
    mWebView = (WebView) findViewById(R.id.webView);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new WebViewClient());

    // confirm the proper url is being pulled out of the intent...
    // An example url is: http://www.voorjaarsdagen.eu/media/com_vjd/vjd_abstracts/2017/A17206.pdf
    // Uncomment to test it directly:  mTargetURLString = "http://www.voorjaarsdagen.eu/media/com_vjd/vjd_abstracts/2017/A17206.pdf" <-- doesn't work, but URL in browser works
    // Uncomment to test it with google mTargetURLString = "http://www.google.com";   <-- works

    Log.d("\n\n\n LOG target url:", mTargetURLString);
    Toast.makeText(this, mTargetURLString, Toast.LENGTH_LONG).show();

    mWebView.loadUrl(mTargetURLString);

}

}

以下是此次调用后直接输出的logcat:

    04-14 14:00:34.639 1259-1259/? E/SELinux: avc:  denied  { find } for service=batteryproperties scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:healthd_service:s0 tclass=service_manager
04-14 14:00:34.771 30309-30434/com.hawthornemackenzie.congressfoundationandroid W/chromium: [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup
04-14 14:00:34.779 30309-30325/com.hawthornemackenzie.congressfoundationandroid D/FA: Connected to remote service
04-14 14:00:34.812 1260-2994/? D/gralloc_ranchu: gralloc_alloc: format 2 and usage 0x933 imply creation of host color buffer
04-14 14:00:34.926 1929-2055/system_process I/ActivityManager: Displayed com.hawthornemackenzie.congressfoundationandroid/.WebActivity: +541ms

[ 04-14 14:00:34.937 30309:30454 D/         ]
HostConnection::get() New Host Connection established 0xa13a5d80, tid 30454
04-14 14:00:34.942 1260-1293/? D/gralloc_ranchu: gralloc_alloc: format 2 and usage 0x933 imply creation of host color buffer
04-14 14:00:35.079 1260-1293/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x933 imply creation of host color buffer
04-14 14:00:35.183 1260-1260/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
04-14 14:00:35.560 30309-30309/com.hawthornemackenzie.congressfoundationandroid W/BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 30309
04-14 14:01:00.129 1260-1327/? D/hwcomposer: hw_composer sent 210 syncs in 60s
04-14 14:02:00.062 1260-1327/? D/hwcomposer: hw_composer sent 2 syncs in 60s

0 个答案:

没有答案