Class AndroidPicturesService

java.lang.Object
com.gluonhq.attach.pictures.impl.AndroidPicturesService
All Implemented Interfaces:
PicturesService

public class AndroidPicturesService extends Object implements PicturesService

Create the file /src/android/res/xml/file_provider_paths.xml with the following content that allows access to the external storage or to a temporal cache in case the picture is not saved:

 
    <?xml version="1.0" encoding="utf-8"?>
    <paths>
        <external-path name="external_files" path="." />
        <external-cache-path name="external_cache_files" path="." />
    </paths>
 
 

The permission android.permission.CAMERA needs to be added as well as the permissions android.permission.READ_EXTERNAL_STORAGE and android.permission.WRITE_EXTERNAL_STORAGE to be able to read and write images. Also a provider is required:

 <manifest package="${application.package.name}" ...>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <application ...>
       ...
       <activity android:name="com.gluonhq.helloandroid.PermissionRequestActivity" />
       <provider
           android:name="com.gluonhq.helloandroid.FileProvider"
           android:authorities="${application.package.name}.fileprovider"
           android:exported="false"
           android:grantUriPermissions="true">
           <meta-data
               android:name="android.support.FILE_PROVIDER_PATHS"
               android:resource="@xml/file_provider_paths" />
       </provider>
   </application>
 </manifest>
 
  • Property Summary

    Properties
    Type
    Property
    Description
    javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.image.Image>
    A read-only property containing the image taken from the camera or gallery or null if it failed, or it was cancelled.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Retrieve an image from the device's gallery of images.
    void
    asyncTakePhoto(boolean savePhoto)
    Use the device's camera to take a photo, and retrieve an Image.
    Retrieve the file associated to the original picture generated by takePhoto(true) or the file related to the picture selected with PicturesService.loadImageFromGallery().
    javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.image.Image>
    A read-only property containing the image taken from the camera or gallery or null if it failed, or it was cancelled.
    Optional<javafx.scene.image.Image>
    Retrieve an image from the device's gallery of images, in a blocking way.
    static void
     
    static void
    setResult(String filePath, int rotate)
     
    Optional<javafx.scene.image.Image>
    takePhoto(boolean savePhoto)
    Use the device's camera to take a photo, in a blocking way, and retrieve an Image.
    static void
    takePicture(boolean savePhoto)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Property Details

    • image

      public javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.image.Image> imageProperty
      Specified by:
      imageProperty in interface PicturesService
      Returns:
      a read-only object property containing an image that can be null
  • Constructor Details

    • AndroidPicturesService

      public AndroidPicturesService()
  • Method Details

    • takePhoto

      public Optional<javafx.scene.image.Image> takePhoto(boolean savePhoto)
      Description copied from interface: PicturesService
      Use the device's camera to take a photo, in a blocking way, and retrieve an Image. It can be saved as well in the device's public album.
      Specified by:
      takePhoto in interface PicturesService
      Parameters:
      savePhoto - if true, image is saved to public album
      Returns:
      an Optional with the Image or empty if it failed, or it was cancelled
    • asyncTakePhoto

      public void asyncTakePhoto(boolean savePhoto)
      Description copied from interface: PicturesService
      Use the device's camera to take a photo, and retrieve an Image. It can be saved as well in the device's public album.
      Specified by:
      asyncTakePhoto in interface PicturesService
      Parameters:
      savePhoto - if true, image is saved to public album
    • loadImageFromGallery

      public Optional<javafx.scene.image.Image> loadImageFromGallery()
      Description copied from interface: PicturesService
      Retrieve an image from the device's gallery of images, in a blocking way.
      Specified by:
      loadImageFromGallery in interface PicturesService
      Returns:
      an Optional with the Image or empty if it failed, or it was cancelled
    • asyncLoadImageFromGallery

      public void asyncLoadImageFromGallery()
      Description copied from interface: PicturesService
      Retrieve an image from the device's gallery of images.
      Specified by:
      asyncLoadImageFromGallery in interface PicturesService
    • getImageFile

      public Optional<File> getImageFile()
      Description copied from interface: PicturesService
      Retrieve the file associated to the original picture generated by takePhoto(true) or the file related to the picture selected with PicturesService.loadImageFromGallery().
      Specified by:
      getImageFile in interface PicturesService
      Returns:
      an Optional with the File associated with the original image.
    • imageProperty

      public javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.image.Image> imageProperty()
      Description copied from interface: PicturesService
      A read-only property containing the image taken from the camera or gallery or null if it failed, or it was cancelled.
      Specified by:
      imageProperty in interface PicturesService
      Returns:
      a read-only object property containing an image that can be null
    • takePicture

      public static void takePicture(boolean savePhoto)
    • selectPicture

      public static void selectPicture()
    • setResult

      public static void setResult(String filePath, int rotate)