Class ImagePicker
-
- All Implemented Interfaces:
public final class ImagePicker
A helper class for launching gallery image picker or a camera for taking a picture.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
ImagePicker.OnImagePickedListener
Interface for listening for image picker results.
-
Constructor Summary
Constructors Constructor Description ImagePicker(FragmentManager fragmentManager, String fragmentTag)
Creates an image picker object, start image picking or capturing by using startImageCapture or startImageGallery
-
Method Summary
Modifier and Type Method Description static boolean
deleteTemporaryFile(@NonNull() Context context, @Nullable() Uri imageUri)
Deletes temporary file previously created by capturing image through camera. void
startImageCapture()
Starts camera application for capturing photos. void
startImageGallery()
Starts image gallery for picking images. boolean
wasStarted()
Returns true
if an image picker request (for gallery or camera) was started and is running orfalse
if none has been started.void
setOnImagePickedListener(@Nullable() ImagePicker.OnImagePickedListener onImagePickedListener)
Sets on image picked listener. -
-
Constructor Detail
-
ImagePicker
ImagePicker(FragmentManager fragmentManager, String fragmentTag)
Creates an image picker object, start image picking or capturing by using startImageCapture or startImageGallery- Parameters:
fragmentManager
- Fragment manager, supplied by the calling activity for fragment stack control.fragmentTag
- Tag to be given to the fragment once added to the layout
-
-
Method Detail
-
deleteTemporaryFile
static boolean deleteTemporaryFile(@NonNull() Context context, @Nullable() Uri imageUri)
Deletes temporary file previously created by capturing image through camera.
- Parameters:
context
- The context to use.imageUri
- Uri of file that should be removed.- Returns:
true
if file was removed, false otherwise.
-
startImageCapture
@UiThread() void startImageCapture()
Starts camera application for capturing photos. Result can be observed by setting listener via setOnImagePickedListener.
This method adds this fragment instance to
fragmentManager
with tagfragmentTag
.
-
startImageGallery
@UiThread() void startImageGallery()
Starts image gallery for picking images. Result can be observed by setting listener via setOnImagePickedListener.
This method adds this fragment instance to
fragmentManager
with tagfragmentTag
.
-
wasStarted
boolean wasStarted()
Returns
true
if an image picker request (for gallery or camera) was started and is running orfalse
if none has been started. This method is useful to let the application determine if another request should be started or not (e.g. after a configuration change).- Returns:
true
if a request was already started by the application and is still running, orfalse
if no request is running.
-
setOnImagePickedListener
void setOnImagePickedListener(@Nullable() ImagePicker.OnImagePickedListener onImagePickedListener)
Sets on image picked listener. If set after some image picking events have already happened, the corresponding method will be called again. Calling this method will replace any previously set listener. You may provide
null
to clear the listener.- Parameters:
onImagePickedListener
- OnImagePickedListener that should be notified, ornull
to clear the listener.
-
-
-
-