Class AndroidPicturesService

  • All Implemented Interfaces:

    public class AndroidPicturesService
    extends java.lang.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"?>
            <external-path name="external_files" path="." />
            <external-cache-path name="external_cache_files" path="." />

    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="${}" ...>
        <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" />
                   android:resource="@xml/file_provider_paths" />
    • Constructor Detail

      • AndroidPicturesService

        public AndroidPicturesService()
    • Method Detail

      • takePhoto

        public java.util.Optional<javafx.scene.image.Image> takePhoto​(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:
        takePhoto in interface PicturesService
        savePhoto - if true, image is saved to public album
        an Optional with the Image or empty if it failed or it was cancelled
      • loadImageFromGallery

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

        public static void takePicture​(boolean savePhoto)
      • selectPicture

        public static void selectPicture()
      • setResult

        public static void setResult​(java.lang.String filePath,
                                     int rotate)