问题
I plan to get the IMEI of the phone in order to generate the QR Code or Barcode in my application. I have check the question before asking. More over I also check the gluon mobile docs for more detail. but It seem not solved my problem. The block code inside ispresent() is never ever been execute. Here is my code
Services.get(DeviceService.class).ifPresent(deviceService -> {
label.setText("Modeld: "+"Test" );
label.setText("Model: "+ deviceService.getModel()+"\nSerial: "+ deviceService.getSerial());
});
Build.gradles
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 = 'fr.cashmag.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:5.0.2'
}
jfxmobile {
downConfig {
version = '3.8.5'
// Do not edit the line below. Use Gluon Mobile Settings in your
project context menu instead
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'fr.cashmag.**.*',
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
The application doesn't seem to show any error in the logcat when I deploy it the the real devices
回答1:
If you check the downConfig
block on your build file, you will notice the list of plugins, or Charm Down services, your app is using:
jfxmobile {
downConfig {
version = '3.8.5'
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
...
}
The jfxmobile
is adding for you for each of those plugins the core artifact and their platform implementations:
dependencies {
compile 'com.gluonhq:charm:5.0.2'
compile 'com.gluonhq:charm-down-plugin-display:3.8.5'
desktopCompile 'com.gluonhq:charm-down-plugin-display-desktop:3.8.5'
androidCompile 'com.gluonhq:charm-down-plugin-display-android:3.8.5'
iosCompile 'com.gluonhq:charm-down-plugin-display-ios:3.8.5'
...
}
Because you also have charm
, it has transitive dependencies in some other services, like device
, but only in the core artifact, so you will be adding:
dependencies {
compile 'com.gluonhq:charm:5.0.2'
compile 'com.gluonhq:charm-down-plugin-device:3.8.5'
...
compile 'com.gluonhq:charm-down-plugin-display:3.8.5'
desktopCompile 'com.gluonhq:charm-down-plugin-display-desktop:3.8.5'
androidCompile 'com.gluonhq:charm-down-plugin-display-android:3.8.5'
iosCompile 'com.gluonhq:charm-down-plugin-display-ios:3.8.5'
...
}
And this is why your project can use DeviceService
.
But you are not adding the platform implementation of that service. So when you run on any platform Services.get(DeviceService.class).get()
will be null.
In this case, all you need to do is add the device
plugin to the list:
Your build will have:
jfxmobile {
downConfig {
version = '3.8.6'
plugins 'device', 'display', 'lifecycle', 'statusbar', 'storage'
}
...
}
Note that you can use Charm Down 3.8.6
now.
来源:https://stackoverflow.com/questions/54439106/problem-on-get-device-information-with-gluon