Reputation: 65
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.
Upvotes: 0
Views: 477
Reputation: 65
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();
}
}
This solved my problem of getting image from gallery and displaying it in imageview like in 'pInterest' application. Thanks :)
Upvotes: 1