[英]implicit intent: shating images from gallery to my app
I'm trying to make the gallery app share images to my app, the problem is that I don't know how to get the image data sent to me by the gallery. 我正在尝试使图库应用程序与我的应用程序共享图像,问题是我不知道如何获取图库发送给我的图像数据。 I assumed that I may found the data in the method .getData() but it returns null
我假设我可以在方法.getData()中找到数据,但它返回null
this is my intent-filter 这是我的意图过滤器
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.VIEW"/>
<data android:mimeType="image/*"/>
<category android:name="android.intent.category.default"/>
</intent-filter>
and here is my code in MainActivity 这是我在MainActivity中的代码
Intent data = getIntent(); //get the intent that starts this activity, in this case: gallery intent
if(data != null){
Uri uri = data.getData();
//set the image view: the problem is: uri is always null
imageView.setImageURI(uri);
}
if the method getData() is not what I want, then how can I get the image that meant to be shared with my app? 如果方法getData()不是我想要的,那么如何获取要与我的应用共享的图像?
So, I think my answer is a little bit late, but anyhow, here it is: 因此,我认为我的回答有点晚了,但是无论如何,这里是:
You have already set the intent-filter in the AndroidManifest.xml correct like this: 您已经在AndroidManifest.xml中正确设置了意图过滤器,如下所示:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
As on this Website stated, you get the URI with this command: 如本网站所述,您可以通过以下命令获取URI:
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
//set content of ImageView to the specific Uri
imageView.setImageURI(imageUri);
Dokumentation about the Intent class can be found here . 关于Intent类的文档可以在这里找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.