如何通过共享选项在imageview中将我选择的图像从库设置为我的应用程序。 [英] How can i set my selected image from gallery to my application in imageview via share option.

查看:83
本文介绍了如何通过共享选项在imageview中将我选择的图像从库设置为我的应用程序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,我可以将我的照片从库分享到我的应用程序,这与PINTEREST的概念相同。但是它通过登录网关进行,如果用户已经登录,那么它会将所选图像设置为imageview或登录以继续相同。共享选项直接来自电话库的共享菜单,就像我们在列表视图中看到的那样,当我们点击图库中的共享选项,即邮件,蓝牙等时。

I am building an application in which I can share my photo from gallery to my application, just the same concept as of 'PINTEREST'. But it undergoes through Login gateway and if a user is already login then it will set the selected image to imageview or either Login to continue the same. The Share option is directly from the share menu of the phone gallery like we see in listview when we click on share option in gallery i.e.,mail, bluetooth etc.

我想要要知道,如何通过图库中的共享选项登录后,如何将所选图像设置为我的应用程序的图像视图。

I want to know,how can I set the selected image to the imageview of my application after login via Share option from gallery.

推荐答案

我得到了我的答案:)
这可以通过使用这样的Intent来完成:

I got my answer :) This can be done by using Intent like this :

Intent intent = getIntent();
// Get the action of the intent
String action = intent.getAction();
// Get the type of intent (Text or Image)
String type = intent.getType();
// When Intent's action is 'ACTION+SEND' and Tyoe is not null
if (Intent.ACTION_SEND.equals(action) && type != null) {
     if (type.startsWith("image/")) { // When type is 'image/*'
           handleSendImage(intent); // Handle single image being sent
       }
}
private void handleSendImage(Intent intent) {
    // Get the image URI from intent
    Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
    // When image URI is not null
    if (imageUri != null) {
        // Update UI to reflect image being shared
        view_news.setImageURI(imageUri);
        news.setVisibility(View.GONE);
    } else{
        Toast.makeText(this, "Error occured, URI is invalid", Toast.LENGTH_LONG).show();
    }
}

这解决了从图库和显示中获取图像的问题它在imageview中像'pInterest'应用程序。
谢谢:)

This solved my problem of getting image from gallery and displaying it in imageview like in 'pInterest' application. Thanks :)

这篇关于如何通过共享选项在imageview中将我选择的图像从库设置为我的应用程序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆