How to open phones gallery through code
Here is sample code for open gallery from app.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE);
OnActivityResult for get image.
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_IMAGE) {
if (resultCode == Activity.RESULT_OK) {
if (data != null) {
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Toast.makeText(getActivity(), "Canceled", Toast.LENGTH_SHORT).show();
}
}
}
How to open built-in gallery app on click button
Add following code to open Gallery app:startActivity(Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,Intent.CATEGORY_APP_GALLERY))
For more info related to CATEGORY_APP_GALLERY
Open Gallery App in Android
I figured out the way..
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"content://media/internal/images/media"));
startActivity(intent);
This piece of code just opened the gallery without any issues. Could get it working on all versions!
Thought to put it as answer for people who are looking to open a Gallery on all versions.
Thanks Guys! :)
android pick images from gallery
Absolutely. Try this:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
Don't forget also to create the constant PICK_IMAGE, so you can recognize when the user comes back from the image gallery Activity:
public static final int PICK_IMAGE = 1;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == PICK_IMAGE) {
//TODO: action
}
}
That's how I call the image gallery. Put it in and see if it works for you.
EDIT:
This brings up the Documents app. To allow the user to also use any gallery apps they might have installed:
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE);
Android Studio: Open phone gallery with image upload button using php/html
Actually your question is not well received but i think that you want to open phone gallery by clicking event.
Am i right?
If it is so then you have to do like this
First of all initialize
private static final int PICK_IMAGE = 1;
then
your_Click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
}
});
Open gallery app from Android Intent
This is what you need:
ACTION_VIEW
Change your code to:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Related Topics
Android Spannablestring Set Background Behind Part of Text
Android Screen Lock/ Unlock Programmatically
Android Studio Create Project Template for New Projects
How to Send a Simple Email Programmatically? (Exists a Simple Way to Do It)
Receiver Not Registered Exception Error
How to Handle the Firebase Notification When App Is in Foreground
Get the Progress Time of the Video Played Under Videoview
Android Take Screenshot via Code
Read Command Output Inside Su Process
Android Device as a Receiver for A2Dp Profile
How to Open Phones Gallery Through Code
How to Ping a Url in an Android Service
Very Large Soap Response - Android- Out of Memory Error
How to Handle Asynctask's in Actionbaractivity Fragments When Viewpager Is Used