0
 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);
       }

in some devices this is working fine.but in few devices it is giving error like file or folder doesn't found please help me in resolving issue

Praveen
  • 33
  • 4

2 Answers2

0

Try to rename the uri from file:///android_assets/ to file:///android_asset/

The correct path for files stored in assets folder is file:///android_asset/xxx with no "s"

For example:

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); 
hungr
  • 2,086
  • 1
  • 20
  • 33
0

try this

 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);
                }
            }

        }
Shyam
  • 6,376
  • 1
  • 24
  • 38