PicturesService Android : Can't take photo. Can't load from gallery more than once.
PicturesService Android :
Has someone already run into this ?
- Can't take photo. Nothing happens.
- Can't access to the gallery more than once.
- Can't access to the gallery after trying to take a picture.
- In all exposed cases, the code following the
takePhotoorloadFromGalleryinstructions is not executed.
No error message.
Works well with the former Gluon Mobile Plugin.

PictureService works just fine, like the rest of Attach services.
Without the code of what you are doing or without a stacktrace of the error you are getting is impossible for me to say why it doesn't work for you.
Things you can try:
- Make sure you include the service in the AttachList, see https://docs.gluonhq.com/#_adding_attach_to_the_project
- Add some printouts to see if your service is created, see https://docs.gluonhq.com/#_using_services
- Enable Attach logs, setting:
System.setProperty(com.gluonhq.attach.util.Constants.ATTACH_DEBUG,"true")(see https://docs.gluonhq.com/attach/javadoc/4.0.13/com.gluonhq.attach.util/com/gluonhq/attach/util/Constants.html#ATTACH_DEBUG) - Build again and deploy to your Android device, see the output of the process and find out if the service is working as expected or not. In that case, find the relevant logs or possible stacktraces and try to fix the possible issues yourself, or if this is not possible or you see that the service is not working as expected, post them here so we can help or file an issue with enough information to reproduce the problem.
Hi @jperedadnr and thanks for all your advice.
I suspect that ShareService affects the Camera permissions in the generated AndroidManifest File.
Platform : Android.
With the example code below
- We can take a photo.
- But if we uncomment the
ShareServicedependency declaration, takephoto method doesn't work.
OS : Linux IDE : NetBeans 13.0 Plugin : Gluonfx GraalVM : graalvm-svm-java17-linux-gluon-22.0.0.3-Final
Steps to reproduce :
- Create a new Gluon-Single Project named
TestTakePhoto - Replace the
pom.xmlandBasicViewcodes with the codes below. - Build, package and install with the
androidprofile. - Try to take a photo, works fine.
- Uncomment
ShareServicedependency. - Made new Build, package and install again.
- Try to take a photo, doesn't work.
Regards.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testtakephoto</groupId>
<artifactId>testtakephoto</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TestTakePhoto</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<javafx.version>18</javafx.version>
<attach.version>4.0.14</attach.version>
<gluonfx.plugin.version>1.0.13</gluonfx.plugin.version>
<javafx.plugin.version>0.0.8</javafx.plugin.version>
<mainClassName>com.testtakephoto.TestTakePhoto</mainClassName>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>com.gluonhq</groupId>
<artifactId>charm-glisten</artifactId>
<version>6.1.0</version>
</dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>display</artifactId>
<version>${attach.version}</version>
</dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>lifecycle</artifactId>
<version>${attach.version}</version>
</dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>statusbar</artifactId>
<version>${attach.version}</version>
</dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>storage</artifactId>
<version>${attach.version}</version>
</dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>util</artifactId>
<version>${attach.version}</version>
</dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>pictures</artifactId>
<version>${attach.version}</version>
</dependency>
<!--
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>share</artifactId>
<version>${attach.version}</version>
</dependency>
-->
</dependencies>
<repositories>
<repository>
<id>Gluon</id>
<url>https://nexus.gluonhq.com/nexus/content/repositories/releases</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>${javafx.plugin.version}</version>
<configuration>
<mainClass>${mainClassName}</mainClass>
</configuration>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
</execution>
<execution>
<!-- Configuration for manual attach debugging -->
<!-- Usage: mvn clean javafx:run@debug -->
<id>debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000</option>
</options>
</configuration>
</execution>
<execution>
<!-- Configuration for automatic IDE debugging -->
<id>ide-debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
</options>
</configuration>
</execution>
<execution>
<!-- Configuration for automatic IDE profiling -->
<id>ide-profile</id>
<configuration>
<options>
<option>${profiler.jvmargs.arg1}</option>
<option>${profiler.jvmargs.arg2}</option>
<option>${profiler.jvmargs.arg3}</option>
<option>${profiler.jvmargs.arg4}</option>
<option>${profiler.jvmargs.arg5}</option>
</options>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.gluonhq</groupId>
<artifactId>gluonfx-maven-plugin</artifactId>
<version>${gluonfx.plugin.version}</version>
<configuration>
<target>${gluonfx.target}</target>
<attachList>
<list>display</list>
<list>lifecycle</list>
<list>statusbar</list>
<list>storage</list>
<list>pictures</list>
<list>share</list>
</attachList>
<mainClass>${mainClassName}</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>ios</id>
<properties>
<gluonfx.target>ios</gluonfx.target>
</properties>
</profile>
<profile>
<id>android</id>
<properties>
<gluonfx.target>android</gluonfx.target>
</properties>
</profile>
</profiles>
</project>
package com.testtakephoto;
import com.gluonhq.attach.pictures.PicturesService;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.Icon;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
public class BasicView extends View {
public BasicView() {
Label label = new Label("\n"
+ "PicturesService Android :\n"
+ "Can't take photo.\n"
+ "Can't load from gallery more than once.\n"
+ "https://github.com/gluonhq/attach/issues/259");
label.setStyle("-fx-text-alignment: center");
setAlignment(label, Pos.CENTER);
ImageView imageView = new ImageView();
imageView.setFitHeight(300);
imageView.setFitWidth(300);
imageView.setPreserveRatio(true);
Button button = new Button("Press the button to take a photo");
button.setGraphic(new Icon(MaterialDesignIcon.LANGUAGE));
button.setMaxWidth(Double.MAX_VALUE);
button.setOnAction(e -> PicturesService.create().ifPresent(service -> {
service.takePhoto(false).ifPresent(image -> imageView.setImage(image));
}));
setStyle("-fx-background-color: antiquewhite;");
setTop(label);
setCenter(imageView);
setBottom(button);
}
@Override
protected void updateAppBar(AppBar appBar) {
appBar.setTitleText("Test Take Photo Application");
}
}
