也许意图的方法是你在找什么。通过设置一个动作到一个意图,比如说,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"));
结果:
这是你在找什么? http://developer.android.com/guide/components/intents-filters.html – curioustechizen 2012-07-31 08:22:35