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.

    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • 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 or false if none has been started.
      void setOnImagePickedListener(@Nullable() ImagePicker.OnImagePickedListener onImagePickedListener) Sets on image picked listener.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 tag fragmentTag.

      • 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 tag fragmentTag.

      • wasStarted

         boolean wasStarted()

        Returns true if an image picker request (for gallery or camera) was started and is running or false 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, or false 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, or null to clear the listener.