【发布时间】:2015-04-24 08:39:01
【问题描述】:
大家好,我想使用 webview 在我的活动中显示 pdf,所以我这样做了:
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.lasergroup.ami.utilities.PDFActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/wv_PDF"/>
</RelativeLayout>
JAVA
WebView wv = (WebView)findViewById(R.id.wv_PDF);
String pdfURL = "http://www.randomurl.com/randompdf.pdf"
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginState(WebSettings.PluginState.ON);
wv.loadUrl("http://docs.google.com/gview?embedded=true&url="+pdfURL);
这在模拟器上运行良好,但是当我在我的设备(LG G3 Android 5.0 API 21)上使用它时,它会在 wv.loadUrl 之后自动打开浏览器(Chrome)。这是一个非常奇怪的问题,所以我想了解它是代码问题还是设备问题,我想知道是否有人可以告诉我为什么会发生这种情况。 我没有任何打开浏览器的意图,所以我无法理解会发生什么(仅在某些设备上)。
【问题讨论】: