I am building an application and in one of my activities, I am displaying some information from a database and one image, this image is scaled down and when the user press the image, I am launching the built-in gallery to view it in a larger size.
My problem here is the following
when I am done looking at the image in the gallery, I want the user when he press the back button to go back to my app and exactly to the activity that launches the gallery, my application show me a crash message and direct me to the main activity of my app
here is the code that launches the built-in gallery
imageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new
File(image_file.getAbsolutePath())),"image/*");
startActivityForResult(intent, 1);
}
});
I tried using startActivity(intent);
but that still not working.
I also tried to override onPuase() and onResume()
but after I did, the entire activity that hold the imageView does not launch and the app crashes.
when I looked up something similar to this problem, people say that I may have bad manifest but I am doing nothing for that Activity in my manifest.
How can I fix the problem so the user can see the image in the built-in or any other gallery app then presses the back button to go back to my app?
thanks
I am not sure but try below code in your on click listener
imageView.setOnClickListener(new View.OnClickListener() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
}
});
Related
I want to see a image in gallery and it's working fine, the problem is that if I click on the top back button, I return to gallery and not to the app. If I click on the back button in the bottom, I go back to the app as it should.
Click here to see the back button that doesnt work
That's the snippet for starting the intent:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + path), "image/*");
activity.startActivityForResult(intent, ChatActivity.GALLERY_INTENT_CALLED);
What you refer as the "top back button" does not go back. It goes where the developer of the app wants it to go. You did not write this gallery app, and so you do not control where it goes.
Google calls this "up navigation", and ostensibly it is supposed to go up a navigational hierarchy within the app that you are in.
In short: this is perfectly normal, it has nothing to do with your code, and there is nothing that you can do about it.
Is there anyway to open Gallery faster through android studio? like the way facebook messenger does or whatsapp does? I making my own app and every time i tap the button to open gallery, it takes a few seconds. (I know it't not because of the phone because other apps open gallery really fast). Actually it's not that slow either but i'd really like it if it opened with a blink of an eye. Although I do have have a lot of computation on the images like resizing and changing orientations in onActivityResult(), but that shouldn't matter should it? btw here is my code for opening the gallery:
public void openGallery(View view)
{
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);//
startActivityForResult(Intent.createChooser(intent, "Select Picture"),IMAGE_GALLERY_REQUEST);
}
Can anyone help me with this?
Are you using Emulator? If so try Device.
I am using this:
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, IMAGE_GALLERY_REQUEST);
It takes only a second or less to open Gallery.
I have a button which opens the android gallery app. I use the code
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"content://media/internal/images/media"));
startActivity(intent);
for Android>=2.3 found here: Open Gallery App in Android
My problem: When the user opens the gallery from my app and leaves gallery (home button, share image,..), then the gallery will show up next time the user opens my app (without button click).
How can I avoid the gallery is shown in my app when opening my app? The gallery should only be shown once when the button is clicked, but not next time my app gets in front.
Your best option given what your requirements appear to be is to tell Android not to save the Gallery in your task's history. That way, when they leave the Gallery activity it will not appear in the task's history stack. Do that by setting a flag on your intent.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"));
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
I'm writing a code for my app, and i got stuck which trying to figure this out.
I want to call GALLERY from by app and then if the user selects an image, that image is brought back to my app for further actions instead of Gallery opening it.
Plz help me coding this, thanks in advance :)
Check here for an answer: Pick an image from the Gallery
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
//intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 1);
I have seen a lot of posts about this, and it seems like the code below should work. I have created an SD Card image and added it to the emulator (and that works fine).
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
//intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 1);
It does launch and allow selection of images, but when I click on an image, everything exits and the emulator returns to the home screen, not the back to my app. My onActivityResult is never called either.
What am I missing?
I found my issue. I was launching the gallery from a sub-activity and that sub activity Intent had the flag FLAG_ACTIVITY_NO_HISTORY which prevented the call back from going to that activity.
thanks.
Use the following intent :
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("return-data", true);
startActivityForResult(intent, 1);