我是android开发的新手。我必须从URL显示PDF。
这是我目前的代码,但我无法显示PDF文件:
public class TestActivity extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.setProperty("http.proxyHost","192.168.0.2");
System.setProperty("http.proxyPort","8080");
showPdf();
}
private void showPdf()
{
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
Log.v("....hello....","");
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
}
}
logcat的:
10-11 14:50:49.586: ERROR/AndroidRuntime(537): FATAL EXCEPTION: main
10-11 14:50:49.586: ERROR/AndroidRuntime(537): android.app.SuperNotCalledException: Activity {com.vidushi.Test/com.vidushi.Test.TestActivity} did not call through to super.onCreate()
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2629)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.os.Looper.loop(Looper.java:123)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at java.lang.reflect.Method.invokeNative(Native Method)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at java.lang.reflect.Method.invoke(Method.java:521)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
这里的工作正常。我仍然建议您测试是否在AndroidManifest.xml文件中添加了INTERNET权限:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
您要打开的链接是:http://litofinter.es.milfoil.arvixe.com/PDF/Book6.pdf
现在它的工作正常: