1

I have two parts to this question: 1) what is the best solution to my need, and 2) how do I do this?

1) I have a client app which sends bundles to a service app. the bundles can break the limit on bundle size, so I need to write the actual request out and read it in on the service side. Because of this, I can't write to my private internal storage. I've used these pages heavily, and haven't had luck: http://developer.android.com/guide/topics/data/data-storage.html http://developer.android.com/training/basics/data-storage/files.html

My current understanding is that my best path is to use this to get a public dir:

File innerDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

I then add in my filename:

String fileName = String.valueOf(request.timestamp + "_avoidRoute"+count+++".ggr");

Combing these two results in the full file path:

/storage/emulated/0/Download/GroundGuidance/Route/1425579692169_avoidRoute1.ggr

Which I write to disk like this:

fos = context.openFileOutput(fullPath, Context.MODE_WORLD_WRITEABLE);
fos.write(routeString.getBytes());
fos.close();

When I try to write this to disk I get the error

java.lang.IllegalArgumentException: File /storage/emulated/0/Download/GroundGuidance/Route/1425579692169_avoidRoute1.ggr contains a path separator

Of course it does - I need it to have a path. I've searched online for solutions to this error which tell me to us FileOutputStream to write a full path. I did, but while my app doesn't error and appears to create the file, I'm also not able to view it on my phone in Windows Explorer, leading me to believe that it is creating a file with private permissions. So this brings me to my post and two questions: 1) Is there a different approach I should be trying to take to share large amounts of data between my client and service apps? 2) If not, what am I missing?

Thanks all for reading and trying to help!

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Jonathan
  • 69
  • 1
  • 10

1 Answers1

1

Combing these two results in the full file path:

/storage/emulated/0/Download/GroundGuidance/Route/1425579692169_avoidRoute1.ggr

Which I write to disk like this:

fos = context.openFileOutput(fullPath, Context.MODE_WORLD_WRITEABLE);

This is not an appropriate use of Context's openFileOutput() method as that does not take a full path, but rather a filename within an app's private storage area.

If you are going to develop a full path yourself, as you have, then use

fos = new FileOutputStream(fullPath)

The Sharing permission setting is not applicable to the External Storage, though you will need a manifest permission to write (and implicitly read) on your creator, and the one for reading on your consumer.

Or, instead of constructing a full path, you could use your private storage with a filename and Context.MODE_WORLD_WRITEABLE (despite the being deprecated as an advisory) and pass the absolute path of the result to the other app to use with new FileInputStream(path).

Or you could use any of the other data interchange methods - content providers, local sockets, etc.

Community
  • 1
  • 1
Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • Ok, thanks. I'm still not sure why I don't see the file in Windows Explorer, even when I put them directly in the Download directory, but when I went back and looked via a file viewer on my android device the files showed up :/. – Jonathan Mar 05 '15 at 19:12