简体   繁体   English

如何从SD卡在Android模拟器中打开PDF文件

[英]How to open a pdf file in android emulator from sdcard

hi i am new to android development. 嗨,我是android开发的新手。 i manually kept a pdf file in emulator sdcard through ddms, and i also installed " adobe reader " in emulator when i tried to read the pdf file in emulator with the following code 我通过ddms手动将pdf文件保存在模拟器sdcard中,并且当我尝试使用以下代码在模拟器中读取pdf文件时,我还在模拟器中安装了“ adobe reader

File file = 
new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/iTunes Connect.pdf");
        Uri path = Uri.fromFile(file);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setDataAndType(path,"application/pdf");
        try 
        {
            startActivity(intent);
        } 
        catch (ActivityNotFoundException e) 
        {
            Toast.makeText(xv.this, 
                getString(R.string.app_name), 
                Toast.LENGTH_SHORT).show();
        }

i am getting the file path is not valid error. 我正在获取文件路径无效错误。

can any one help me in this. 谁能在这方面帮助我。

use %20 (for white space) in between iTunes and 20Connect.pdf . iTunes20Connect.pdf之间使用%20 (用于空格)。

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/iTunes%20Connect.pdf");

I think this will solve your problem 我认为这可以解决您的问题

try out this path 试试这条路

File file=new File("/sdcard/iTunes Connect.pdf");

I think this will work for u 我认为这对你有用

I think you should not use hard coded file paths. 我认为您不应该使用硬编码的文件路径。 The framework will give you the base path of the area you want to save files to. 该框架将为您提供要将文件保存到的区域的基本路径。

For SD card you should, use Environment.getExternalStorageDirectory() 对于SD卡,应使用Environment.getExternalStorageDirectory()

local files you should, use Context.getFilesDir() (or Context.openFileOutput(String name, int mode), etc) 您应该使用的本地文件,请使用Context.getFilesDir()(或Context.openFileOutput(字符串名称,整数模式)等)

local cache you should, use Context.getCacheDir() 您应该使用本地缓存,请使用Context.getCacheDir()

For emulator you can try File file=new File("mnt/sdcard/iTunes Connect.pdf"); 对于仿真器,您可以尝试File file = new File(“ mnt / sdcard / iTunes Connect.pdf”);

I think that your emulator have not adob reader install please check first it is install or not 我认为您的模拟器尚未安装Adobe Reader,请先检查是否已安装

 File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename);
    Intent target = new Intent(Intent.ACTION_VIEW);
    target.setDataAndType(Uri.fromFile(file),"application/pdf");
    target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

    Intent intent = Intent.createChooser(target, "Open File");
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        // Instruct the user to install a PDF reader here, or something
    }   `enter code here`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM