0

I want to read a text file present in a different directory i.e Games Directory(/sdcard/Android/data/game_package_name/files) from my android app.

Is there any way to do so, if yes then please suggest.

Note: This is for production level application, so please avoid any root-specific features.

1 Answers1

0

Basically, you cannot access another application's sandbox. However, if you can modify the other application, you can use a ContentProvider or similar sharing solution to provide access to this specific file from other applications.

Store the shared file in a shared folder

As you want to access the file from different applications and the sandbox from one will not be available from the other, you should write your file in a directory accessible from both, for example:

String fileName = Environment.getExternalStorageDirectory().getPath() + "myFolderForBothApplications/myFileNameForBothApplications.txt";

Use a Content Provider

If you prefer to keep your file as part of one application, you can still expose the information via a ContentProvider. In it, override the public ParcelFileDescriptor openFile(Uri uri, String mode) method, and in the other application, just use the method getContentResolver().openInputStream(...).

And here a few links to related topics where I shamelessly copied/pasted code from:

Community
  • 1
  • 1
w00ly
  • 455
  • 1
  • 5
  • 18