Android 文件或文件夹不存在';从资产打开PDF时不存在

Android 文件或文件夹不存在';从资产打开PDF时不存在,android,android-intent,android-assets,Android,Android Intent,Android Assets,在某些设备中,这可以正常工作。但在少数设备中,它会出现错误,例如找不到文件或文件夹。请帮助我解决此问题。尝试从重命名urifile:///android_assets/至file:///android_asset/ 存储在资产文件夹中的文件的正确路径为file:///android_asset/xxx不带“s” 例如: try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAn

在某些设备中,这可以正常工作。但在少数设备中,它会出现错误,例如找不到文件或文件夹。请帮助我解决此问题。

尝试从
重命名urifile:///android_assets/
file:///android_asset/

存储在资产文件夹中的文件的正确路径为
file:///android_asset/xxx
不带“s”

例如:

 try {
         Intent intent = new Intent(Intent.ACTION_VIEW);
         intent.setDataAndType(Uri.parse("file:///android_assets"+"/abc.pdf"),
             "application/pdf");

         startActivity(intent);
       } catch (Exception e) {
       WriteLogToFile.appendLog(Dashboard.this, "File", "file.txt", ActivityUtil.writeException(e));
         Intent i = new Intent(Intent.ACTION_VIEW);
         i.setData(Uri.parse("market://details?id=com.adobe.reader&hl=en"));
         startActivity(i);
       }
试试这个

Intent intent = new Intent(Intent.ACTION_VIEW);  
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);  
Uri uri = Uri.fromFile(new File("file:///android_asset/abc.pdf"));  
intent.setDataAndType (uri, "application/pdf");  
this.startActivity(intent); 

确保坏掉的手机有pdf查看器?
 public class SampleActivity extends Activity
        {

            @Override
            protected void onCreate(Bundle savedInstanceState)
            {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                CopyReadAssets();

            }

            private void CopyReadAssets()
            {
                AssetManager assetManager = getAssets();

                InputStream in = null;
                OutputStream out = null;
                File file = new File(getFilesDir(), "abc.pdf");
                try
                {
                    in = assetManager.open("abc.pdf");
                    out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);

                    copyFile(in, out);
                    in.close();
                    in = null;
                    out.flush();
                    out.close();
                    out = null;
                } catch (Exception e)
                {
                    Log.e("tag", e.getMessage());
                }

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(
                        Uri.parse("file://" + getFilesDir() + "/abc.pdf"),
                        "application/pdf");

                startActivity(intent);
            }

            private void copyFile(InputStream in, OutputStream out) throws IOException
            {
                byte[] buffer = new byte[1024];
                int read;
                while ((read = in.read(buffer)) != -1)
                {
                    out.write(buffer, 0, read);
                }
            }

        }