2

I created the SQLite DB using the following code:

context.openOrCreateDatabase(dbName, Context.MODE_WORLD_READABLE, null);

And tried to send it as attachment by email using the following code:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND)
        .setType("message/rfc822")
        .putExtra(android.content.Intent.EXTRA_STREAM,
                Uri.fromFile(getDatabasePath(dbName)));
startActivity(Intent.createChooser(emailIntent, null));

This opens the GMail compose activity with the attachment icon. But the recipient did not receive the attachment.

This has been asked before. But it looks like there is no solution other than to copy the db file to SD card.

My question then is: What is the use of the MODE_WORLD_READABLE flag if another app like GMail is unable to read the file?

Community
  • 1
  • 1
Dheeraj Vepakomma
  • 26,870
  • 17
  • 81
  • 104
  • It doesn't seems straight forward to send a database using e-mail. use some serialization method.. anyway application in android are sandboxed and this might be the reason for the problem. when using attachment or other kind of share method you must assure the file is outside the sandbox. – ApriOri Jun 21 '12 at 09:20
  • @Erb What is the use of the `MODE_WORLD_READABLE` flag if the file is sandboxed? – Dheeraj Vepakomma Jun 21 '12 at 09:52

1 Answers1

0

Let's say we have 2 apps app_1 and app_2 on android filesystem, those 2 apps lay on /data/data/app_1 and /data/data/app_2 where app_1 is the "user" app_1

if you run ls on /data/data you'll see something like this: drwxr-x--x app_1 app_1 drwxr-x--x app_2 app_2

MODE_WORLD_READABLE is equivalent to the Unix command a+r [file] This however does not allow other users/application to access the file since the directory permissions does not allow app_1 to access files on the app_2 folder.

In fact , app_1 won't be even able to ls /data/data to see a list of all other directories. bottom line, the MODE_WORLD_READBLE is only useful when you deal with files on a shared storage like the sdcard but not on the jailed sandbox that each application is running.

I hope this information is helpful.

ApriOri
  • 2,618
  • 29
  • 48
  • PS if you want to test this behaviour and you have root on your device/emulator you can do something like cd /data/data and then su app_1 and then try to access files of another app on /data/data/app_2 – ApriOri Jun 21 '12 at 17:53