如何显示从android.intent.action.SEND
在接收到的图像的ImageView
?
用户从应用程序列表我的应用程序共享图像。该图像是通过故意发送
和我的活动打开了,但如何使用该图片在ImageView的?
使用
位图的缩略图=(位图)getIntent()getExtras()获得(数据)。;
没有帮助以及
getIntent()。getType()返回图像/ JPG
解决方案
正在receving形象的意图,所以,你必须更新你的表现为:
<活动机器人:名称=。Your_Activity>
...
...
<意向滤光器>
...
<作用机器人:名称=android.intent.action.SEND/>
<类机器人:名称=android.intent.category.DEFAULT/>
<数据机器人:MIMETYPE =图像/ */>
&所述; /意图滤光器>
< /活动
然后活动需要:
无效的onCreate(包savedInstanceState){
...
//获取意图,行动和MIME类型
意向意图= getIntent();
串动= intent.getAction();
字符串类型= intent.getType();
如果(Intent.ACTION_SEND.equals(行动)及和放大器;类型!= NULL){
如果(type.startsWith(图像/)){
乌里imageUri =(URI)intent.getParcelableExtra(Intent.EXTRA_STREAM);
如果(imageUri!= NULL){
YourImageView.setImageUri(imageUri);
}
}
。
。
。
How to display an Image received from an "android.intent.action.SEND"
in an imageview
?
The user selects my app from the list of apps to share an image. The image is sent via intent
and my activity opens up but how to use this image in an imageview?
using
Bitmap thumbnail = (Bitmap) getIntent().getExtras().get("data");
does not help and
getIntent().getType() returns image/jpg
解决方案
You are receving Image in Intent, So you have to update your Manifest as:
<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
Then Activity needs:
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);
}
}
.
.
.