Module com.gluonhq.attach.pictures
Package com.gluonhq.attach.pictures.impl
Class AndroidPicturesService
- java.lang.Object
-
- com.gluonhq.attach.pictures.impl.AndroidPicturesService
-
- All Implemented Interfaces:
PicturesService
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"?> <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 permissionsandroid.permission.READ_EXTERNAL_STORAGE
andandroid.permission.WRITE_EXTERNAL_STORAGE
to be able to read and write images. Also aprovider
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>
-
-
Constructor Summary
Constructors Constructor Description AndroidPicturesService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<java.io.File>
getImageFile()
Retrieve the file associated to the original picture generated bytakePhoto(true)
or the file related to the picture selected withPicturesService.loadImageFromGallery()
.java.util.Optional<javafx.scene.image.Image>
loadImageFromGallery()
Retrieve an image from the device's gallery of imagesstatic void
selectPicture()
static void
setResult(java.lang.String filePath, int rotate)
java.util.Optional<javafx.scene.image.Image>
takePhoto(boolean savePhoto)
Use the device's camera to take a photo, and retrieve anImage
.static void
takePicture(boolean savePhoto)
-
-
-
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 anImage
. It can be saved as well in the device's public album.- Specified by:
takePhoto
in interfacePicturesService
- 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
-
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 interfacePicturesService
- Returns:
- an Optional with the Image or empty if it failed or it was cancelled
-
getImageFile
public java.util.Optional<java.io.File> getImageFile()
Description copied from interface:PicturesService
Retrieve the file associated to the original picture generated bytakePhoto(true)
or the file related to the picture selected withPicturesService.loadImageFromGallery()
.- Specified by:
getImageFile
in interfacePicturesService
- Returns:
- an Optional with the File associated with the original image.
-
takePicture
public static void takePicture(boolean savePhoto)
-
selectPicture
public static void selectPicture()
-
setResult
public static void setResult(java.lang.String filePath, int rotate)
-
-