Reputation: 55
I want to let other app access my app's data, I find the Google Drive app can do. For example, I have app A, there is a file located in /data/data/Package A name/cache/1.txt, I want app B can access it,
try
{
FileInputStream fin = new FileInputStream("/data/data/Package A name/cache/1.txt");
Integer i = fin.available();
Log.w("test", i.toString());
}
catch (Exception e)
{
Log.w("test", e);
}
In fact, Google Drive app has this feature, I download file 1.txt from Google Drive, it is /data/data/com.google.android.apps.docs/files/fileinternal/d36323c59e1519308c702675c4394e51/1.txt, it is Google Drive private data, however, I write app C, code is this
try
{
FileInputStream fin = new FileInputStream("/data/data/com.google.android.apps.docs/files/fileinternal/d36323c59e1519308c702675c4394e51/1.txt");
Integer i = fin.available();
Log.w("test", i.toString());
}
catch (Exception e)
{
Log.w("test", e);
}
app C can access it, it seems like Google Drive app open the file's access permission, so other app can access. Thanks in advance.
Upvotes: 1
Views: 614
Reputation: 55
Context.openFileOutput can create file with MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE which is accessed by other app, it is located in /data/data/Package name/files folder, that's Google Drive do, by the way, Android doesn't suggest these constants, this constant was deprecated in API level 17 and you should use more formal mechanism for interactions such as ContentProvider, BroadcastReceiver, and Service.
Upvotes: 0
Reputation: 2601
You should read about sending and receiving content between applications, about content providers and return here with better question.
And also see this example
Upvotes: 1