in the iOS world data can be exchanged between applications through the use of Open Protocol. For example if I have an e-mail with a pdf attachment I can open it into PDFExpert, even if the apps runs on a SandBox and they don't have share file system.

In case of Android I noticed that such a procedure is different, for example I can save a document into the file system let's say /mnt/Apps_Name and then I can reopen that document in an other apps.

Is there a way to have the user to experience data/documents exchanging between apps like in the iOS World? Do you have any example? Some references to the official documentation? Do they need some Bonjour or Zero Conf implementation?

有帮助吗?

解决方案

Maybe the Intent approach is what you are looking for. By setting an action to an Intent, let's say for example, ACTION_VIEW, you set the corresponding data in the Intent (i.e. a pdf file), and the system determines which apps are capable of showing that information. If more than one app are capable, usually a dialog promps to let the user decide the app.

View PDF example:

Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
startActivity(intent);

Intents feature is one of my favourites in Android Development. See for example how easy is to share any file/text/image/... without the pain of implementing any Oauth/Oauth2....

Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
String toShare = "This is the text to share";
// You can add extras
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");

// Start intent with choose prompt
startActivity(Intent.createChooser(intent, "Share via"));

Result:

enter image description here

其他提示

Android 4.1 adds Network Service Discovery which should be exactly what you want — seems to actually be implemented on top of Bonjour under the hood.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top