Thursday, February 9, 2012

[android-developers] Pitfalls of sharing app data between users

I have an app where you can save the state into a custom file and
share with another user of the same app.
This saved state consists of several jpgs and a text file, archived
into a single zip file.

When the user wants to share, they are prompted with the usual chooser
which supports the Send action for the file type. The most obvious and
useful choice will be as an email attachment, but I am not restricting
it to that.

Then I register my app for Viewing or Opening that file type so
another user can open the received file in my app.

All well and good, my problem is the MIME type I choose for the
attached zip file, and the resultant behaviour when sharing.

The obvious candidate is to use the application/zip MIME type. The
problem is that while this works fine on the default android mail app
it is not supported by Gmail or the default Samsung email app, any zip
file attachment recieved on those mail clients simply won't open. It
seems to be a recognized issue with Gmail, has anyone any experience
to the contrary? Samsung support have acknowledged it is an issue with
their email client, in fact they only support text, image and media
files as email attachments.
With Samsung being the major player it is and the Gmail app being so
popular, that gives me a bit of a problem! It seems wrong to provide a
feature which will not work on many (if not most!) devices.

My lesser of two evils approach is then to keep my zip file format,
but change the MIME type when sharing so that it will work in more
email clients. Changing to the Text/Plain format and registering for
this type works on all email clients I have tried, with some caveats.
For example, K9 will only send it if the file has a .txt extension.

That approach has its own set of issues:

Firstly when sharing I get a lot of potential candidates for the Text/
Plain type which are not really appropriate such as Twitter, Facebook,
Messaging, WhatsApp etc. They don't attach the file but consume it as
text. Is there a way to restrict it to apps which are actually going
to attach it or send it on as is? I guess not, but I'll ask anyway.

For what its worth, here is my sharing code.

Intent myMessageIntent = new
Intent(android.content.Intent.ACTION_SEND);
myMessageIntent.setType("text/plain");
Uri fileUri =Uri.fromFile(mytemporaryfile);
myMessageIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
myMessageIntent.putExtra(Intent.EXTRA_TITLE, "title");
myMessageIntent.putExtra(Intent.EXTRA_SUBJECT, "Attached: xxx");
startActivityForResult(myMessageIntent ,EMAIL_PRESET);

Secondly, as I am now registering for the text/plain type, I can
potentially receive all types of text data which my app is not
interested in. Unfortunately I can't do much about that, apart from
perhaps maybe using a custom file extension and checking for that, but
I have to keep it as .txt if I want it to work in K9. Obviously I
elegantly handle the situations where it receives which is not
originally sourced from my app, but it is still a poor user
experience.

So I seem to be between a rock and a hard place.

A. If I use anything but text, image or media MIME types, many email
clients won't open the attachment.
B. If I fake one of these standard MIME types then email clients work,
but all sorts of non-relevant apps can share my attachment, and I am
registered for all receiving all data of that type, not just mine.
C. If I use a custom MIME type then it solves B, but then they wont
open in email clients, so I am back to A.

At the moment it looks like I am stuck with B, with the poor user
experience that entails.

So is there a better approach? How does everyone else handle this, it
can't be that unusual a requirement, can it?

Regards
James

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment