2012-07-31 72 views
1

在iOS世界中的数据可以通过使用开放协议在应用程序之间交换。例如,如果我有一封带有pdf附件的电子邮件,我可以将其打开到PDFExpert中,即使这些应用程序在SandBox上运行并且它们没有共享文件系统。Android - 开放协议(Bonjour)就像iOS上的

在Android的情况下,我注意到这样的过程是不同的,例如我可以将文档保存到文件系统中让我们说/ mnt/Apps_Name,然后我可以在其他应用程序中重新打开该文档。

有没有办法让用户体验iOS应用程序中的应用程序之间交换数据/文档?你有什么样的例子吗?对官方文档的一些引用?他们是否需要一些Bonjour或Zero Conf的实施?

+1

这是你在找什么? http://developer.android.com/guide/components/intents-filters.html – curioustechizen 2012-07-31 08:22:35

回答

2

也许意图的方法是你在找什么。通过设置一个动作到一个意图,比如说,ACTION_VIEW,你在意图(即一个PDF文件)中设置相应的数据,系统决定哪些应用程序能够显示该信息。如果有多个应用程序有能力,通常会有一个对话框提示用户决定应用程序。

查看PDF例如:

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

意图的特点是我在Android的发展的最爱之一。例如,见是多么容易分享任何文件/文字/图片/ ...没有实施任何的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")); 

结果:

enter image description here