use*_*770 1 pdf android android-intent
为什么每次我尝试使用以下代码在我的SDCARD中打开pdf文件时,它实际上并不打开pdf文件本身,而是进入adobe reader菜单?我的代码有什么问题吗?
Intent intent = new Intent();
File pdfFile = new File("/sdcard/sample.pdf");
Uri path = Uri.fromFile(pdfFile);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(path);
intent.setType("application/pdf");
intent.setPackage("com.adobe.reader");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
Lux*_*ode 12
不,没有错.您已将类型设置为pdf并将包指定为adobe.reader.这样做是为了在adobe reader中启动pdf.没有使用库(或自己编写代码)来呈现PDF并显示它们,就无法直接在应用程序中显示pdf.
请注意,如果您只设置类型而不是包,系统将找到可用于显示PDF的任何应用程序
编辑
你可以尝试类似的东西
Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File( filename );
intent.setDataAndType( Uri.fromFile( file ), "application/pdf" );
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
要么
Intent intent = new Intent();
intent.setPackage("com.adobe.reader");
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14171 次 |
| 最近记录: |