我仍然无法让Charm Down PicturesService工作。 (我已经就此问题发布了question。
现在我创建了一个非常简单的测试应用程序,并使用最新的库版本更新了build.gradle文件。 但是,PicturesService仍然非常不可靠。选择图片有时会起作用,有时则不然。拍照似乎更加不可靠。
buildscript {
repositories {
jcenter()
}
dependencies { classpath 'org.javafxports:jfxmobile-plugin:1.3.5'}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonapplication.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:4.3.4'
compile 'org.javafxports:jfxdvk:8.60.9'
compileNoRetrolambda 'com.airhacks:afterburner.mfx:1.6.2'
}
jfxmobile {
downConfig {
version = '3.3.0'
plugins 'display', 'lifecycle', 'statusbar', 'storage', 'pictures'
}
android {
manifest = 'src/android/AndroidManifest.xml'
compileSdkVersion = '23'
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'license/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
}
}
必要的权限将添加到AndroidManifest:
<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"/>
流动应用:
public class GluonApplication extends MobileApplication {
@Override
public void init() {
addViewFactory(HOME_VIEW, () ->
{
PicturesService pictureService = Services.get(PicturesService.class)
.orElseThrow(() -> new IllegalStateException("Failed to get PictureService"));
Button btnLoadImage = new Button("load image");
btnLoadImage.setOnAction(e -> pictureService.loadImageFromGallery().ifPresent(i -> imv.setImage(i)));
CheckBox chkSavePicture = new CheckBox("save picture");
Button btnTakePhoto = new Button("take photo");
btnTakePhoto.setOnAction(e -> pictureService.takePhoto(chkSavePicture.isSelected()).ifPresent(i -> imv.setImage(i)));
ImageView imv= new ImageView();
imv.setFitHeight(300);
imv.setFitWidth(300);
VBox content = new VBox(16, btnLoadImage, btnTakePhoto, chkSavePicture, imv);
content.setAlignment(Pos.CENTER);
return new View(content);
});
}
}
在华为P9 lite,Android 6.0上测试
Logcat拍照成功:
05-13 16:08:49.200: V/FXActivity(18796): onActivityResult with requestCode 2 and resultCode = -1 and intent = null
05-13 16:08:50.180: V/FXActivity(18796): onRestart
05-13 16:08:50.187: V/FXActivity(18796): onStart
05-13 16:08:50.187: V/FXActivity(18796): onResume
05-13 16:08:50.196: V/FXEntity(18796): Surface created.
05-13 16:08:50.198: V/FXActivity native(18796): [JVDBG] SURFACE created native android window at 0xe7c9b208, surface = 0xffac4e60
05-13 16:08:50.202: D/mali_winsys(18796): new_window_surface returns 0x3000
05-13 16:08:50.202: I/GLASS(18796): Native code is notified that surface has changed (repaintall)!
05-13 16:08:50.203: V/FXEntity(18796): Called Surface changed [1080, 1740], format 4
05-13 16:08:50.203: V/FXActivity native(18796): [JVDBG] SURFACE created native android window at 0xe7c9b208, surface = 0xffac4e40
05-13 16:08:50.204: I/GLASS(18796): Native code is notified that surface has changed with size provided (repaintall)!
05-13 16:08:50.204: V/FXEntity(18796): Called Surface redraw needed
05-13 16:08:50.205: V/FXEntity(18796): Redraw...
05-13 16:08:50.205: I/GLASS(18796): Call surfaceRedrawNeeded
05-13 16:08:50.205: I/GLASS(18796): Native code is notified that surface needs to be redrawn (repaintall)!
05-13 16:08:50.205: V/FXEntity(18796): Wait a while before doing this again...
05-13 16:08:50.230: I/System.out(18796): PPSRenderer: scenario.effect - createShader: LinearConvolveShadow_20
05-13 16:08:50.310: I/System.out(18796): PPSRenderer: scenario.effect - createShader: LinearConvolveShadow_28
05-13 16:08:50.408: V/FXEntity(18796): Redraw again...
05-13 16:08:50.408: I/GLASS(18796): Call surfaceRedrawNeeded
05-13 16:08:50.408: I/GLASS(18796): Native code is notified that surface needs to be redrawn (repaintall)!
05-13 16:08:50.416: I/OpenGLRenderer(18796): Initialized EGL, version 1.4
05-13 16:08:50.419: D/mali_winsys(18796): new_window_surface returns 0x3000
Logcat拍照失败:
05-13 22:18:38.264: I/art(9381): Late-enabling -Xcheck:jni
05-13 22:18:38.299: D/ActivityThread(9381): ActivityThread,attachApplication
05-13 16:07:13.229: D/HwCust(18033): Create obj success use class android.content.res.HwCustHwResourcesImpl
05-13 16:07:13.393: I/MultiDex(18033): VM with version 2.1.0 has multidex support
05-13 16:07:13.393: I/MultiDex(18033): install
05-13 16:07:13.393: I/MultiDex(18033): VM has multidex support, MultiDex support library is disabled.
05-13 16:07:13.429: V/FXActivity(18033): Initializing JavaFX Platform, using 8.60.9-SNAPSHOT
05-13 16:07:13.438: V/FXActivity native(18033): Loading JavaFXDalvik library
05-13 16:07:13.452: V/HwPolicyFactory(18033): : success to get AllImpl object and return....
05-13 16:07:13.474: I/HwCust(18033): Constructor found for class android.app.HwCustHwWallpaperManagerImpl
05-13 16:07:13.474: D/HwCust(18033): Create obj success use class android.app.HwCustHwWallpaperManagerImpl
05-13 16:07:13.475: V/ActivityThread(18033): ActivityThread,callActivityOnCreate
05-13 16:07:13.482: I/System.out(18033): usetextureview = false, useswipekeyboard = false
05-13 16:07:13.484: I/HwSecImmHelper(18033): mSecurityInputMethodService is null
05-13 16:07:13.485: V/FXActivity(18033): onCreate called, using 8.60.9-SNAPSHOT
05-13 16:07:13.486: V/FXActivity native(18033): Notification queue instance created.
05-13 16:07:13.486: V/FXActivity native(18033): Notification queue started
05-13 16:07:13.498: V/HwWidgetFactory(18033): : successes to get AllImpl object and return....
05-13 16:07:13.542: V/FXActivity native(18033): appDataDir: /data/user/0/com.gluonapplication
05-13 16:07:13.543: V/FXActivity(18033): onStart
05-13 16:07:13.544: D/ActivityThread(18033): add activity client record, r= ActivityRecord{a0b6377 token=android.os.BinderProxy@a432176 {com.gluonapplication/javafxports.android.FXActivity}} token= android.os.BinderProxy@a432176
05-13 16:07:13.544: V/FXActivity(18033): onActivityResult with requestCode 2 and resultCode = -1 and intent = null
05-13 16:07:13.544: V/FXActivity(18033): onResume
05-13 16:07:13.566: D/OpenGLRenderer(18033): Use EGL_SWAP_BEHAVIOR_PRESERVED: false
05-13 16:07:13.638: I/OpenGLRenderer(18033): Initialized EGL, version 1.4
05-13 16:07:13.655: D/mali_winsys(18033): new_window_surface returns 0x3000
05-13 16:07:13.665: V/FXEntity(18033): Surface created.
05-13 16:07:13.666: V/FXActivity native(18033): [JVDBG] SURFACE created native android window at 0xe7c99d08, surface = 0xffac4f30
05-13 16:07:13.816: I/System.out(18033): user.locale=de-DE
05-13 16:07:13.816: I/System.out(18033): javax.xml.stream.XMLEventFactory=com.sun.xml.stream.events.ZephyrEvent...
05-13 16:07:13.816: I/System.out(18033): prism.text=native
05-13 16:07:13.816: I/System.out(18033): java.vendor.url=http://www.android.com/
05-13 16:07:13.816: I/System.out(18033): java.ext.dirs=
05-13 16:07:13.816: I/System.out(18033): line.separator=
05-13 16:07:13.816: I/System.out(18033): file.encoding=UTF-8
05-13 16:07:13.816: I/System.out(18033): java.runtime.version=0.9
05-13 16:07:13.816: I/System.out(18033): prism.dirtyopts=true
05-13 16:07:13.816: I/System.out(18033): user.name=root
05-13 16:07:13.816: I/System.out(18033): java.compiler=
05-13 16:07:13.816: I/System.out(18033): android.icu.unicode.version=7.0
05-13 16:07:13.816: I/System.out(18033): javax.xml.stream.XMLOutputFactory=com.sun.xml.stream.ZephyrWriterFactory
05-13 16:07:13.816: I/System.out(18033): prism.debugfonts=true
05-13 16:07:13.816: I/System.out(18033): com.sun.javafx.gestures.rotate=true
05-13 16:07:13.816: I/System.out(18033): java.version=0
05-13 16:07:13.816: I/System.out(18033): android.icu.library.version=55.1
05-13 16:07:13.816: I/System.out(18033): use.egl=true
05-13 16:07:13.816: I/System.out(18033): embedded=monocle
05-13 16:07:13.816: I/System.out(18033): com.sun.javafx.gestures.scroll=true
05-13 16:07:13.816: I/System.out(18033): prism.lcdtext=false
05-13 16:07:13.816: I/System.out(18033): os.arch=armv7l
05-13 16:07:13.816: I/System.out(18033): java.io.tmpdir=/data/user/0/com.gluonapplication/cache
05-13 16:07:13.816: I/System.out(18033): glass.platform=Monocle
05-13 16:07:13.816: I/System.out(18033): android.zlib.version=1.2.8
05-13 16:07:13.816: I/System.out(18033): user.language=de
05-13 16:07:13.816: I/System.out(18033): java.vm.version=2.1.0
05-13 16:07:13.816: I/System.out(18033): com.sun.javafx.isEmbedded=true
05-13 16:07:13.816: I/System.out(18033): javax.xml.stream.XMLInputFactory=com.sun.xml.stream.ZephyrParserFactory
05-13 16:07:13.816: I/System.out(18033): prism.glDepthSize=16
05-13 16:07:13.816: I/System.out(18033): path.separator=:
05-13 16:07:13.816: I/System.out(18033): java.runtime.name=Android Runtime
05-13 16:07:13.816: I/System.out(18033): java.specification.version=0.9
05-13 16:07:13.816: I/System.out(18033): user.dir=/
05-13 16:07:13.816: I/System.out(18033): prism.maxTextureSize=2048
05-13 16:07:13.816: I/System.out(18033): java.vm.specification.vendor=The Android Project
05-13 16:07:13.816: I/System.out(18033): com.sun.javafx.gestures.zoom=true
05-13 16:07:13.816: I/System.out(18033): java.vm.name=Dalvik
05-13 16:07:13.816: I/System.out(18033): monocle.platform=Android
05-13 16:07:13.816: I/System.out(18033): log.lens=FINEST
05-13 16:07:13.816: I/System.out(18033): java.vm.specification.version=0.9
05-13 16:07:13.816: I/System.out(18033): user.home=
05-13 16:07:13.816: I/System.out(18033): java.specification.name=Dalvik Core Library
05-13 16:07:13.816: I/System.out(18033): file.separator=/
05-13 16:07:13.816: I/System.out(18033): java.library.path=/vendor/lib:/system/lib
05-13 16:07:13.816: I/System.out(18033): user.variant=
05-13 16:07:13.816: I/System.out(18033): os.version=3.10.90-g033208c
05-13 16:07:13.816: I/System.out(18033): java.boot.class.path=/system/framework/core-libart.jar:/sy...
05-13 16:07:13.816: I/System.out(18033): DALVIK.prism.verbose=true
05-13 16:07:13.816: I/System.out(18033): java.vm.specification.name=Dalvik Virtual Machine Specification
05-13 16:07:13.816: I/System.out(18033): javafx.platform=android
05-13 16:07:13.816: I/System.out(18033): glass.lens=eglfb
05-13 16:07:13.816: I/System.out(18033): os.name=Linux
05-13 16:07:13.816: I/System.out(18033): user.region=DE
05-13 16:07:13.816: I/System.out(18033): java.class.path=.
05-13 16:07:13.816: I/System.out(18033): android.icu.impl.ICUBinary.dataPath=/data/misc/zoneinfo/current/icu:/syst...
05-13 16:07:13.816: I/System.out(18033): prism.verbose=true
05-13 16:07:13.816: I/System.out(18033): prism.vsync=false
05-13 16:07:13.816: I/System.out(18033): java.specification.vendor=The Android Project
05-13 16:07:13.816: I/System.out(18033): java.vm.vendor=The Android Project
05-13 16:07:13.816: I/System.out(18033): prism.allowhidpi=true
05-13 16:07:13.816: I/System.out(18033): java.vendor=The Android Project
05-13 16:07:13.816: I/System.out(18033): http.agent=Dalvik/2.1.0 (Linux; U; Android 6.0; ...
05-13 16:07:13.816: I/System.out(18033): android.icu.cldr.version=27.0.1
05-13 16:07:13.816: I/System.out(18033): android.openssl.version=BoringSSL
05-13 16:07:13.817: I/System.out(18033): java.home=/system
05-13 16:07:13.817: I/System.out(18033): java.vm.vendor.url=http://www.android.com/
05-13 16:07:13.817: I/System.out(18033): java.class.version=50.0
05-13 16:07:13.817: V/DalvikLauncher(18033): Launch JavaFX application on DALVIK vm.
05-13 16:07:13.848: V/DalvikLauncher(18033): We have JavaFX on our current (base) classpath, registered exit listener
05-13 16:07:13.854: V/DalvikLauncher(18033): application class: [class com.gluonapplication.GluonApplication]
05-13 16:07:13.854: V/DalvikLauncher(18033): preloader class: [null]
05-13 16:07:13.854: V/DalvikLauncher(18033): javafx application class: [class javafx.application.Application]
05-13 16:07:13.854: V/DalvikLauncher(18033): javafx launcher class: [class com.sun.javafx.application.LauncherImpl]
05-13 16:07:13.854: V/DalvikLauncher(18033): launch application method: [public static void com.sun.javafx.application.LauncherImpl.launchApplication(java.lang.Class,java.lang.Class,java.lang.String[])]
05-13 16:07:13.871: V/FXEntity(18033): Called Surface changed [1080, 1740], format 4
05-13 16:07:13.871: V/FXActivity native(18033): [JVDBG] SURFACE created native android window at 0xe7c99d08, surface = 0xffac4f10
05-13 16:07:13.871: V/FXEntity(18033): Called Surface redraw needed
05-13 16:07:13.878: V/FXEntity(18033): Called Surface redraw needed
05-13 16:07:13.993: I/System.out(18033): Prism pipeline init order: es2
05-13 16:07:13.993: I/System.out(18033): Using native-based Pisces rasterizer
05-13 16:07:13.993: I/System.out(18033): Using dirty region optimizations
05-13 16:07:13.993: I/System.out(18033): Using system sized mask for primitives
05-13 16:07:13.993: I/System.out(18033): Not forcing power of 2 sizes for textures
05-13 16:07:13.993: I/System.out(18033): Using hardware CLAMP_TO_ZERO mode
05-13 16:07:13.993: I/System.out(18033): Opting in for HiDPI pixel scaling
05-13 16:07:14.000: I/System.out(18033): Prism pipeline name = com.sun.prism.es2.ES2Pipeline
05-13 16:07:14.010: I/System.out(18033): Loading ES2 native library ... prism_es2_monocle
05-13 16:07:14.023: I/System.out(18033): succeeded.
05-13 16:07:14.023: I/System.out(18033): GLFactory using com.sun.prism.es2.MonocleGLFactory
05-13 16:07:14.054: I/GLASS(18033): I have to Call dlopen libGLESv2.so
05-13 16:07:14.055: I/GLASS(18033): handle = 0xf76fcd04
05-13 16:07:14.055: I/GLASS(18033): I have to Call dlopen libEGL.so
05-13 16:07:14.056: I/GLASS(18033): handle = 0xf76fc9c4
05-13 16:07:14.057: I/GLASS(18033): Binding to libactivity.so
05-13 16:07:14.058: I/GLASS(18033): GetNativeWindow = 0xf3762da1, getDensitiy = 0xf3762dad
05-13 16:07:14.058: V/FXEntity(18033): notify_glassHasStarted called in FXActivity. register device now.
05-13 16:07:14.079: D/mali_winsys(18033): new_window_surface returns 0x3000
05-13 16:07:14.089: I/System.out(18033): (X) Got class = class com.sun.prism.es2.ES2Pipeline
05-13 16:07:14.104: I/System.out(18033): Initialized prism pipeline: com.sun.prism.es2.ES2Pipeline
05-13 16:07:14.127: I/DENSITY(18033): GETDENSITY, answer = 3.000000
05-13 16:07:14.185: I/System.out(18033): Maximum supported texture size: 8192
05-13 16:07:14.186: I/System.out(18033): Maximum texture size clamped to 2048
05-13 16:07:14.186: I/System.out(18033): Non power of two texture support = true
05-13 16:07:14.186: I/System.out(18033): Maximum number of vertex attributes = 16
05-13 16:07:14.186: I/System.out(18033): Maximum number of uniform vertex components = 4096
05-13 16:07:14.186: I/System.out(18033): Maximum number of uniform fragment components = 4096
05-13 16:07:14.186: I/System.out(18033): Maximum number of varying components = 60
05-13 16:07:14.186: I/System.out(18033): Maximum number of texture units usable in a vertex shader = 16
05-13 16:07:14.186: I/System.out(18033): Maximum number of texture units usable in a fragment shader = 16
05-13 16:07:14.190: I/System.out(18033): Graphics Vendor: ARM
05-13 16:07:14.191: I/System.out(18033): Renderer: Mali-T830
05-13 16:07:14.192: I/System.out(18033): Version: OpenGL ES 3.1 v1.r8p0-01dev0.bbfc5a14ef62ccdf784a9fff6af72acd
05-13 16:07:14.216: I/System.out(18033): register device done
05-13 16:07:14.227: W/System.err(18033): vsync: false vpipe: true
05-13 16:07:14.227: I/System.out(18033): [MON] Create device
05-13 16:07:14.230: I/System.out(18033): [MON] Create device done, add done
05-13 16:07:14.414: W/System.err(18033): Loading FontFactory com.sun.javafx.font.freetype.FTFactory
05-13 16:07:14.414: W/System.err(18033): Subpixel: enabled
05-13 16:07:14.434: W/System.err(18033): Freetype2 Loaded (version 2.5.0)
05-13 16:07:14.434: W/System.err(18033): LCD support Enabled
05-13 16:07:14.444: W/art(18033): Before Android 4.1, method void com.sun.javafx.scene.transform.TransformUtils$ImmutableTransform.ensureCanTransform2DPoint() would have incorrectly overridden the package-private method in javafx.scene.transform.Transform
05-13 16:07:14.630: W/System.err(18033): Temp file created: /data/user/0/com.gluonapplication/cache/+JXF415078203.tmp
05-13 16:07:14.643: W/System.err(18033): Temp file created: /data/user/0/com.gluonapplication/cache/+JXF1552782793.tmp
05-13 16:07:14.650: W/System.err(18033): Temp file created: /data/user/0/com.gluonapplication/cache/+JXF-728135178.tmp
05-13 16:07:14.657: W/System.err(18033): Temp file created: /data/user/0/com.gluonapplication/cache/+JXF-646868817.tmp
05-13 16:07:14.828: W/art(18033): Before Android 4.1, method double javafx.scene.text.TextFlow.computeChildPrefAreaHeight(javafx.scene.Node, javafx.geometry.Insets) would have incorrectly overridden the package-private method in javafx.scene.layout.Region
05-13 16:07:14.828: W/art(18033): Before Android 4.1, method double javafx.scene.text.TextFlow.computeChildPrefAreaWidth(javafx.scene.Node, javafx.geometry.Insets) would have incorrectly overridden the package-private method in javafx.scene.layout.Region
05-13 16:07:15.067: I/System.out(18033): max rectangle texture cell size = 62
05-13 16:07:15.084: I/System.out(18033): wrap rectangle texture = 2 x 2
05-13 16:07:15.087: I/System.out(18033): ES2ResourceFactory: Prism - createStockShader: AlphaTexture_Color.frag
05-13 16:07:15.106: I/System.out(18033): ES2ResourceFactory: Prism - createStockShader: Texture_Color.frag
05-13 16:07:15.122: I/System.out(18033): PPSRenderer: scenario.effect - createShader: LinearConvolveShadow_20
05-13 16:07:15.133: I/System.out(18033): ES2ResourceFactory: Prism - createStockShader: Solid_TextureRGB.frag
05-13 16:07:15.150: I/System.out(18033): ES2ResourceFactory: Prism - createStockShader: FillRoundRect_Color.frag
05-13 16:07:15.154: I/System.out(18033): Loading Prism common native library ...
05-13 16:07:15.163: I/System.out(18033): succeeded.
05-13 16:07:15.177: I/System.out(18033): PPSRenderer: scenario.effect - createShader: LinearConvolveShadow_28