0

Error: The document path is not valid

I want to store pdf in internal storage and after I want to read It.

I seen many que in this site but none help me out.

My code working file in Environment.getExternalStorageDirectory() now I used getCacheDir() for internal storage.

for write pdf

 FileOutputStream fos = new FileOutputStream(file);
                fos.write(baf.toByteArray());
                fos.close();

file write is completed , I can see file in cache folder.

for read pdf

file = new File(getCacheDir()+ File.separator+fileName);

PackageManager packageManager = getPackageManager();
            Intent testIntent = new Intent(Intent.ACTION_VIEW);
            testIntent.setType("application/pdf");
            List list = packageManager.queryIntentActivities(testIntent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            if (list.size() > 0 && file.isFile()) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                Uri uri = Uri.fromFile(file);
                intent.setDataAndType(uri, "application/pdf");
                startActivity(intent);
            }

I got error "The documenty path is not valid"

Nick
  • 351
  • 3
  • 7
  • 22
  • Your are trying to share the internal storage(Cache Directory) of one application with other application which is not allowed in Android. – AndroidDev Oct 21 '13 at 07:28

1 Answers1

0

use getFilesDir () for internal Storage

public abstract File getFilesDir ()

Added in API level 1 Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.

Returns Returns the path of the directory holding application files. See Also openFileOutput(String, int) getFileStreamPath(String) getDir(String, int)

ex.

File yourFile = context.getFilesDir() + "/" + "file_name";

Look here for details

Mukesh Kumar Singh
  • 4,512
  • 2
  • 22
  • 30