Android open image in gallery with slide through images - android

I am developing Android camera app, and would like to have feature that is in most of camera apps:
Clicking on the preview icon opens the gallery, that shows current photo and allows to swipe through all images in the camera folder.
When I use Intent.ACTION_VIEW, the gallery shows only 1 image, without possibility to look through other photos in the directory.
Are there any extra flags for intent Intent.ACTION_VIEW to get such behavior?
Is there any workaround to get such behavior?

Are there any extra flags for intent Intent.ACTION_VIEW to get such behavior?
No.
There is no requirement that an Android device have an app that is capable of "shows current photo and allows to swipe through all images in the camera folder". For those devices that happen to have such an app, there is no standard Intent structure that demands that the app "shows current photo and allows to swipe through all images in the camera folder".
Is there any workaround to get such behavior?
Write your own UI for this.

#CommonsWare might sound a bit harsh, but if you're going to make an App, don't expect you'd need just some magic Intent calls that do all the work for you.
For the kind of thing you want to achieve, look at ViewPager that gives you something to swipe between different views (each of which would then show one image). Chris Bane has provided a nice custom view that allows to view, zoom and scroll pictures: https://github.com/chrisbanes/PhotoView

OpenCamera AlmalenceGUI.openExternalGallery() uses undocumented action="com.android.camera.action.REVIEW" which in my android-4.2.2 opens the gallery in swipe mode.
private void openExternalGallery(Uri uri)
{
try
{
Intent intent = new Intent("com.android.camera.action.REVIEW", uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
ApplicationScreen.instance.startActivity(intent);
} catch (ActivityNotFoundException ex)
{
try
{
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
ApplicationScreen.instance.startActivity(intent);
} catch (ActivityNotFoundException e)
{
Log.e("AlmalenceGUI", "review image fail. uri=" + uri, e);
}
}
}

Related

Android - how to open image in gallery with delete option

I use following code to open an image in the gallery:
public void onItemClicked(PictureItem item){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri imageUri = FileProvider.getUriForFile(getApplicationContext(), "myapp.fileprovider", new File(item.uri.getPath()));
intent.setDataAndType(imageUri, "image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
This shows my photo in the gallery, but in a 'read-only' mode. I want to be able to delete the image from there, just as if I opened it directly in the gallery.
Which action do I have to use for that? I do not want to use pick, just normal view with the option to delete. I tried ACTION_EDIT but it's not supported (and not quite the right choice neither ...).
I use following code to open an image in the gallery
First, there are hundreds, if not thousands, of "gallery" apps available for Android.
Second, your code simply asks to view an image (with a broken Intent due to your wildcard MIME type). There is no requirement for the app that responds to be a "gallery" app.
I want to be able to delete the image from there, just as if I opened it directly in the gallery.
Then implement that yourself, in your own app, and get rid of the ACTION_VIEW Intent.
Which action do I have to use for that?
There is no Intent action that says "please display this image, but only if you are a gallery app, and, oh, by the way, you must offer a delete option", which appears to be what you want.

Android custom keyboard ,sending media

I have developed an custom keyboard and also added some images to the view,
my goal is to send the clicked image directly to the current app(for eg: message app or watsapp).So, How can i implement this one?
You cannot do that right now in the form you wish. The connection between the currently opened application and keyboard accepts only text (emoticons are text, too). What you can do is to send Intent to the currently opened application and hope, that app will handle that:
public void passImage(String uri) {
Log.d(ImageKeyboard.class.getSimpleName(), "Image passed: " + uri);
Intent intent = createIntent(getApplicationContext(), getCurrentInputBinding(), uri);
try {
getApplicationContext().startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
public Intent createIntent (Context context, InputBinding inputBinding, String uri) {
String[] packageNames = context.getPackageManager().getPackagesForUid(inputBinding.getUid());
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
sharingIntent.setType("image/*");
sharingIntent.setPackage(packageNames[0]);
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(uri));
return sharingIntent;
}
SMS app, Facebook and Gmail will work that way, however any other app may not. This is the best you can do right now.
Important info:
From Android 7.1 Developer Preview it is possible. Info from the site:
Android 7.1 also adds these much-requested developer features to the
platform:
Image keyboard support — expands the types of content that users can enter from their keyboards, letting them express themselves
through custom stickers, animated gifs, and more. Apps can tell the
keyboard what types of content they accept, and keyboards can deliver
all of the images and other content that they offer to the user. For
broad compatibility, this API will also be available in the support
library.

Android Intent.ACTION_PICK

This code successfully retrieves images from the (emulator) SDcard:
public void pickImage(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_IMAGE_GET);
}
}
This returns a bunch of thumbnails titled Choose Picture. Is there any way I can intercept this and filter out certain images first?
Clicking any thumbnail image then runs the OnActivityResult which I can intercept, but then it is too late.
I am using Metadator-extractor and only need to display images containing certain tags, but do not know how to access each
thumbnail before it arrives on the screen.
Is there any way I can intercept this and filter out certain images first?
Not with ACTION_PICK. You are welcome to query MediaStore for available pictures and implement your own pick activity, in which you can filter out whatever you want.

Android camera intent confusion

I am working on an app in which i have to click a pic a pic and save it to a specified folder. I am using android.provider.MediaStore.ACTION_IMAGE_CAPTURE in intent to invoke the camera .I am done with coding and my activity is working fine.But now i have a question in my mind that whether i should stick with this code or i should use the code given here.Need your precious suggestions on this topic.
Thanx in advance.
If you want to just click a picture and save it to a specified folder nothing more then You can use Intent and call ACTION_IMAGE_CAPTURE, it easy to let handle on camera activity do your stuff,
And If your application has some serious deep work with camera when you want to modify preview screen size, and all those things,(For this you have to handle all things like to manage camera, and when to release it, check for don't freeze main UI..) then you have to go with the code you suggested...
Choice is yours.....
I suggest you use the code from your link.
Because most of the stock camera apps don't work as expected with Image Capture. For example the Galaxy S2 and most other Samsung and HTC phones give you the picture bytes back and also save the picture in the standard DCIM Folder on SD-Card, if you want it or not.
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d(TAG, "No SDCARD");
} else {
mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",
"PIC"+System.currentTimeMillis()+".jpg");
mTempImagePath = mImageFile.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
}
this what u r searching i am thinking..

modified android ACTION_VIEW intent

I execute the following code:
Uri uri =
Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
imageIdStr); Intent intent = new
Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setData(uri);
activity.startActivity(intent);
which opens the image viewer activity but I don't want to see the navigation arrows as well as the items in the menu. I only want the zoom controls. Is it possible to have it like that ?
That depends on the application that's actually displaying the image. On Android 2.0 and older, it's probably the Gallery app. On many Android 2.1+ apps, it's probably CoolIris' gallery. If the user has one of the many gallery apps from the market installed, it's up to those apps. I highly doubt there's a standardized extra to control that.
If you're really concerned about what the image display looks like, then you should handle that yourself. If you're really just trying to display an image (and maybe add pinch-zoom support?), it's a reasonable scope.

Categories

Resources