title: Android error testing picture service and location service with Gluon Mobile
body: <p>I'm testing the barcodescanservice, the locationservice and the pictureservice in a simple BasicView with 3 buttons. The barcodescanservice is ok, but the pictureservice produces a nullpointer error in AndroidPicturesService.java:132. The positionservice an AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. In the two cases the program breaks.</p>
  
  <p>I'm using org.javafxports:jfxmobile-plugin:1.3.16 and com.gluonhq:charm:5.0.2. Tested in Android 4.4.4 and Android 8.0 with the same result. The code is copied from the Api Doc.</p>
  
  <p>The code:</p>
  
  <pre><code>        Button butFoto = new Button("Photo");
          butFoto.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent event) {
                  Services.get(PicturesService.class).ifPresent(service -&gt; {
                      service.takePhoto(false).ifPresent(image -&gt; imageView.setImage(image));
                  });
  
              }
          });
  
          Button butBarcode = new Button("Barcode");
          butBarcode.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent event) {
                  String barcodeValue = Services.get(BarcodeScanService.class)
                          .flatMap(service -&gt; service
                          .scan("Scan Test", "Place a barcode under the camera", "Barcode found with value"))
                          .orElse("No barcode found");
                  System.out.println("Scanned Bar Code: " + barcodeValue);
                  label2.setText(barcodeValue);
              }
          });
  
          Button butGPS = new Button("Position");
          butGPS.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent event) {
                  Services.get(PositionService.class)
                          .ifPresent(positionService -&gt; {
                              positionService.start();
                              ReadOnlyObjectProperty&lt;Position&gt; positionProperty = positionService.positionProperty();
                              Position position = positionProperty.get();
                              label2.setText("Lat=" + String.valueOf(position.getLatitude())
                                      + " Lon=" + String.valueOf(position.getLongitude()));
                          });
              }
          });
  </code></pre>
  
  <p>Android manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cip.cipgesfx" android:versionCode="1" android:versionName="1.0"&gt;
      &lt;supports-screens android:xlargeScreens="true"/&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.CAMERA"/&gt;
      &lt;uses-permission android:name="android.permission.FLASHLIGHT" /&gt;
  
      &lt;uses-sdk android:minSdkVersion="4" android:targetSdkVersion="21"/&gt;
  
      &lt;application android:label="cipmobile" android:name="android.support.multidex.MultiDexApplication" android:icon="@mipmap/cip_icono"&gt;
          &lt;activity android:name="javafxports.android.FXActivity" android:label="CipMobile" android:configChanges="orientation|screenSize"&gt;
              &lt;meta-data android:name="main.class" android:value="com.cipmobile.Cipmobile"/&gt;
              &lt;meta-data android:name="debug.port" android:value="0"/&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN"/&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER"/&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;activity android:name="com.gluonhq.impl.charm.down.plugins.android.scan.zxing.CaptureActivity"
                    android:screenOrientation="sensorPortrait"
                    android:clearTaskOnLaunch="true"
                    android:stateNotNeeded="true"
                    android:windowSoftInputMode="stateAlwaysHidden"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.gluonhq.charm.down.plugins.android.scan.SCAN"/&gt;
                  &lt;category android:name="android.intent.category.DEFAULT"/&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;activity android:name="com.gluonhq.impl.charm.down.plugins.android.PermissionRequestActivity" /&gt;
  
          &lt;service android:name="com.gluonhq.impl.charm.down.plugins.android.AndroidPositionBackgroundService" 
                   android:process=":positionBackgroundService" /&gt;
  
      &lt;/application&gt;
  &lt;/manifest&gt;
  
  </code></pre>
  
  <p>Build Gradle:</p>
  
  <pre><code>buildscript {
      repositories {
          jcenter()
      }
      dependencies {
          classpath 'org.javafxports:jfxmobile-plugin:1.3.16'
      }
  }
  
  apply plugin: 'org.javafxports.jfxmobile'
  
  repositories {
      jcenter()
      maven {
          url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
      }
  }
  
  mainClassName = 'com.cip.cipgesfx.IniciarApli'
  
  dependencies {
      compile 'com.gluonhq:charm:5.0.2'
      compile fileTree(dir: 'lib', include: ['*.jar'])
      //compile 'org.eclipse.persistence:org.eclipse.persistence.jpa:2.6.3'
      // https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.jpa
      compile group: 'org.eclipse.persistence', name: 'org.eclipse.persistence.jpa', version: '2.7.4'
      // https://mvnrepository.com/artifact/org.controlsfx/controlsfx
      compile group: 'org.controlsfx', name: 'controlsfx', version: '8.40.14'
      // https://mvnrepository.com/artifact/com.google.code.gson/gson
      compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
      // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
      compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.8'
  }
  
  jfxmobile {
      downConfig {
          version = '3.8.6'
          // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
          plugins 'barcode-scan', 'display', 'lifecycle', 'pictures', 'position', 'statusbar', 'storage'
      }
      android {
          manifest = 'src/android/AndroidManifest.xml'
          dexOptions {
              javaMaxHeapSize '3g'
          }
          androidSdk='/home/cesar/Android/Sdk'
          packagingOptions {
              exclude 'META-INF/LICENSE.txt'
              exclude 'META-INF/NOTICE.txt'
              exclude 'META-INF/DEPENDENCIES.txt'
              exclude 'META-INF/LICENSE.txt'
              exclude 'META-INF/NOTICE.txt'
              exclude 'META-INF/NOTICE'
              exclude 'META-INF/LICENSE'
              exclude 'META-INF/DEPENDENCIES'
              exclude 'META-INF/notice.txt'
              exclude 'META-INF/license.txt'
              exclude 'META-INF/dependencies.txt'
              exclude 'META-INF/INDEX.LIST'
              exclude 'META-INF/LGPL2.1'
              exclude 'license.html'
              exclude 'readme.html'
              exclude 'LICENSE.txt'
              exclude 'NOTICE.txt'
              pickFirst 'META-INF/eclipse.inf'
          }
          compileSdkVersion=21
      }
      ios {
          infoPList = file('src/ios/Default-Info.plist')
          forceLinkClasses = [
                  'com.gluonhq.**.*',
                  'javax.annotations.**.*',
                  'javax.inject.**.*',
                  'javax.json.**.*',
                  'org.glassfish.json.**.*'
          ]
      }
  }
  
  </code></pre>
  
  <p>Stacktrace error for picture service:</p>
  
  <pre><code>04-21 19:31:13.678 5482-5514/com.cip.cipgesfx I/GLASS: Call InternalSurfaceView_onMultiTouchEventNative
  04-21 19:31:13.678 5482-5514/com.cip.cipgesfx I/GLASS: Glass will pass multitouchevent to monocle with count = 1
  04-21 19:31:13.678 5482-5514/com.cip.cipgesfx I/System.out: don't add points, primary = -1
  04-21 19:31:13.688 5482-5514/com.cip.cipgesfx I/AndroidPicturesService: Picture file: file:/storage/emulated/0/Pictures/IMG_20190421_193113.jpg
  04-21 19:31:13.708 5482-5514/com.cip.cipgesfx E/AndroidRuntime: FATAL EXCEPTION: JavaFX Application Thread
      Process: com.cip.cipgesfx, PID: 5482
      java.lang.NullPointerException
          at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:584)
          at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:558)
          at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
          at com.gluonhq.charm.down.plugins.android.AndroidPicturesService.takePicture(AndroidPicturesService.java:132)
          at com.gluonhq.charm.down.plugins.android.AndroidPicturesService.takePhoto(AndroidPicturesService.java:95)
          at com.cipmobile.BasicView$2.lambda$handle$1(BasicView.java:50)
          at com.cipmobile.BasicView$2$$Lambda$1.accept(BasicView.java)
          at java.util.Optional.ifPresent(Optional.java:154)
          at com.cipmobile.BasicView$2.handle(BasicView.java:49)
          at com.cipmobile.BasicView$2.handle(BasicView.java:46)
          at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
          at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
          at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
          at javafx.event.Event.fireEvent(Event.java:198)
          at javafx.scene.Node.fireEvent(Node.java:8411)
          at javafx.scene.control.Button.fire(Button.java:185)
          at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
          at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
  
  </code></pre>
  
  <p>Stacktrace error for location service:</p>
  
  <pre><code>04-21 19:33:28.648 5544-5568/com.cip.cipgesfx I/AndroidPositionService: Available location providers on this device: [passive, gps, network].
  04-21 19:33:28.648 5544-5568/com.cip.cipgesfx I/AndroidPositionService: Picked network as best location provider.
  04-21 19:33:28.648 5544-5568/com.cip.cipgesfx I/AndroidPositionService: Location provider network is not enabled, starting intent to ask user to activate the location provider.
  04-21 19:33:28.668 5544-5568/com.cip.cipgesfx E/AndroidRuntime: FATAL EXCEPTION: JavaFX Application Thread
      Process: com.cip.cipgesfx, PID: 5544
      android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
          at android.app.ContextImpl.startActivity(ContextImpl.java:1112)
          at android.app.ContextImpl.startActivity(ContextImpl.java:1093)
          at android.content.ContextWrapper.startActivity(ContextWrapper.java:311)
          at com.gluonhq.charm.down.plugins.android.AndroidPositionService.initialize(AndroidPositionService.java:179)
          at com.gluonhq.charm.down.plugins.android.AndroidPositionService.start(AndroidPositionService.java:110)
          at com.gluonhq.charm.down.plugins.android.AndroidPositionService.start(AndroidPositionService.java:99)
          at com.cipmobile.BasicView$4.lambda$handle$0(BasicView.java:75)
          at com.cipmobile.BasicView$4$$Lambda$1.accept(BasicView.java)
          at java.util.Optional.ifPresent(Optional.java:154)
          at com.cipmobile.BasicView$4.handle(BasicView.java:74)
          at com.cipmobile.BasicView$4.handle(BasicView.java:70)
          at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
          at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
          at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
          at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
          at javafx.event.Event.fireEvent(Event.java:198)
          at javafx.scene.Node.fireEvent(Node.java:8411)
          at javafx.scene.control.Button.fire(Button.java:185)
          at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
          at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
  
  </code></pre>
  
  <p>I expect the camera to open when clicking the Photo Button but an exception arises. The same when clicking the GPS Button.</p>