我正在开发一个我想在“分享”列表中注册的应用。该部分已经在清单文件中使用以下标记:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/*"/>
<data android:mimeType="image/*"/>
</intent-filter>
在查看SO上的一些示例并使用每个相关问题的一些部分之后,我已经整理了一段简单(但又笨拙)的代码,截至目前,这些代码接收了从库中共享的图像。我也能够将收到的图像成功上传到Facebook。
我的问题是,我希望我的应用可以分享来自各种应用的各种内容。例如,来自Twitter的推文,来自浏览器的URL等。如何确定从我的应用程序的另一个应用程序共享的数据/内容的确切性质?我可以适当地处理收到的数据。但我很难理解如何分析共享的内容。
我用于共享图像的代码是:
注意:我目前在onCreate()
方法中运行这段代码,没有任何错误检查。当我对所关注的问题有所了解时,我会把它们放到位。
ImageView imgSelectedPhoto = (ImageView)findViewById(R.id.imgDisplaySelectedImage);
Uri imageURI = (Uri) getIntent().getExtras().get(Intent.EXTRA_STREAM);
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageURI));
try {
Utility.scaleImage(getApplicationContext(), imageURI);
imgSelectedPhoto.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
非常感谢任何帮助/建议/建议。
答案 0 :(得分:3)
您可以获取应用程序收到的意图的MIME类型数据:
String type = getIntent().getType();