目前我有一个pdf网址,我想简单地使用意图打开它,但是,如果我把网址放在意图中它不起作用
我的代码是这样的,它总是抛出ActivityNotFoundException错误
Intent intent = new Intent(Intent.ACTION_VIEW);intent.setDataAndType(Uri.parse(law.url), "application/pdf");try { startActivity(intent);} catch (ActivityNotFoundException e){ Utility.showErrorDialog( ctx,ctx.getResources().getString(R.string.sys_in, ctx.getResources().getString(R.string.err_no_pdf_reader), ctx.getResources().getString(R.string.close));}
我也尝试了goolge doc方法,但是我的客户拒绝了这个,所以我没有使用这种方法
Intent intent = new Intent(Intent.ACTION_VIEW);intent.setDataAndType(Uri.parse("http://docs.Google.com/vIEwer?url=" + publish.get(Integer.parseInt((String) vIEw.getTag())).pdfURL), "text/HTML"); ctx.startActivity(intent);
感谢帮助
Log cat错误更新
04-23 18:18:50.487: E/AndroIDRuntime(17161): androID.content.ActivityNotFoundException: No Activity found to handle Intent { act=androID.intent.action.VIEW dat=http://oshc.zizsoft.com/oshc_testing.pdf typ=application/pdf }04-23 18:18:50.487: E/AndroIDRuntime(17161): at androID.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1568)04-23 18:18:50.487: E/AndroIDRuntime(17161): at androID.app.Instrumentation.execStartActivity(Instrumentation.java:1439)04-23 18:18:50.487: E/AndroIDRuntime(17161): at androID.app.Activity.startActivityForResult(Activity.java:3356)04-23 18:18:50.487: E/AndroIDRuntime(17161): at androID.app.Activity.startActivityForResult(Activity.java:3317)04-23 18:18:50.487: E/AndroIDRuntime(17161): at androID.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:848)04-23 18:18:50.487: E/AndroIDRuntime(17161): at androID.support.v4.app.Fragment.startActivity(Fragment.java:878)04-23 18:18:50.487: E/AndroIDRuntime(17161): at com.example.oshpedia.Fragment.Shelf.onItemClick(Shelf.java:142)04-23 18:18:50.487: E/AndroIDRuntime(17161): at it.sephiroth.androID.library.Widget.AdapterVIEw.performItemClick(AdapterVIEw.java:299)04-23 18:18:50.487: E/AndroIDRuntime(17161): at it.sephiroth.androID.library.Widget.AbsHListVIEw.performItemClick(AbsHListVIEw.java:972)04-23 18:18:50.487: E/AndroIDRuntime(17161): at it.sephiroth.androID.library.Widget.AbsHListVIEw$PerformClick.run(AbsHListVIEw.java:2511)04-23 18:18:50.487: E/AndroIDRuntime(17161): at it.sephiroth.androID.library.Widget.AbsHListVIEw.run(AbsHListVIEw.java:3200)04-23 18:18:50.487: E/AndroIDRuntime(17161): at androID.os.Handler.handleCallback(Handler.java:615)04-23 18:18:50.487: E/AndroIDRuntime(17161): at androID.os.Handler.dispatchMessage(Handler.java:92)04-23 18:18:50.487: E/AndroIDRuntime(17161): at androID.os.Looper.loop(Looper.java:137)04-23 18:18:50.487: E/AndroIDRuntime(17161): at androID.app.ActivityThread.main(ActivityThread.java:4882)04-23 18:18:50.487: E/AndroIDRuntime(17161): at java.lang.reflect.Method.invokeNative(Native Method)04-23 18:18:50.487: E/AndroIDRuntime(17161): at java.lang.reflect.Method.invoke(Method.java:511)04-23 18:18:50.487: E/AndroIDRuntime(17161): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)04-23 18:18:50.487: E/AndroIDRuntime(17161): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:556)04-23 18:18:50.487: E/AndroIDRuntime(17161): at dalvik.system.NativeStart.main(Native Method)
解决方法:
您可以通过以下两种方式之一查看或下载pdf,即在设备内置浏览器中打开或通过将其嵌入应用程序在webvIEw中打开.
要在浏览器中打开pdf,
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pdf_url));startActivity(browserIntent);
而不是在webvIEw中打开,
WebvIEw webVIEw = (WebVIEw) findVIEwByID(R.ID.webVIEw1); webVIEw.getSettings().setJavaScriptEnabled(true); webVIEw.loadUrl(pdf_url);
总结 以上是内存溢出为你收集整理的通过android intent打开在线pdf文件?全部内容,希望文章能够帮你解决通过android intent打开在线pdf文件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)