如何在 imageview
中显示从 "android.intent.action.SEND"
接收到的图像?
用户从应用程序列表中选择我的应用程序来共享图像。图像通过 Intent 发送
并且我的 Activity 打开,但如何在 ImageView 中使用此图像?
使用
Bitmap thumbnail = (Bitmap) getIntent().getExtras().get("data");
没有帮助并且
getIntent().getType() returns image/jpg
最佳答案
您正在 Intent 中接收图像,因此您必须将 list 更新为:
<activity android:name=".Your_Activity" >
...
...
<intent-filter>
...
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity
那么Activity需要:
void onCreate (Bundle savedInstanceState) {
...
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (type.startsWith("image/")) {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
YourImageView.setImageUri(imageUri);
}
}
.
.
.
关于android - 在 imageview 中显示来自 Intent 的 jpg 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11590881/