Java 使用胶子获取设备信息时出现的问题

Java 使用胶子获取设备信息时出现的问题,java,gluon-mobile,Java,Gluon Mobile,我计划获取手机的IMEI,以便在我的应用程序中生成二维码或条形码。在提问之前,我必须核对一下这个问题。更多信息,我还查看了Glion mobile文档以了解更多详细信息。但这似乎并没有解决我的问题。ispresent()中的块代码从未执行过。这是我的密码 Services.get(DeviceService.class).ifPresent(deviceService -> { label.setText("Modeld: "+"Test" );

我计划获取手机的IMEI,以便在我的应用程序中生成二维码或条形码。在提问之前,我必须核对一下这个问题。更多信息,我还查看了Glion mobile文档以了解更多详细信息。但这似乎并没有解决我的问题。ispresent()中的块代码从未执行过。这是我的密码

Services.get(DeviceService.class).ifPresent(deviceService -> {
            label.setText("Modeld: "+"Test" );
            label.setText("Model: "+ deviceService.getModel()+"\nSerial: "+ deviceService.getSerial());
        });
格拉德斯先生

  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.**.*'
    ]
}
}

当我将应用程序部署到实际设备时,它在logcat中似乎没有显示任何错误

如果您检查构建文件上的
downConfig
块,您将注意到插件列表,或魅力关闭服务,您的应用程序正在使用:

jfxmobile {
     downConfig {
        version = '3.8.5'
        plugins 'display', 'lifecycle', 'statusbar', 'storage'
     }
...
}
jfxmobile
为每个插件添加了核心工件及其平台实现:

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'
    ...
}
因为您还有
charm
,它在一些其他服务中具有可传递的依赖关系,如
device
,但仅在核心工件中,因此您将添加:

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'
    ...
}
这就是为什么您的项目可以使用
DeviceService

但您没有添加该服务的平台实现。因此,当您在任何平台上运行时,
Services.get(DeviceService.class).get()
将为空

在这种情况下,您只需将
设备
插件添加到列表中:

您的构建将具有:

jfxmobile {
     downConfig {
        version = '3.8.6'
        plugins 'device', 'display', 'lifecycle', 'statusbar', 'storage'
     }
...
}

请注意,您现在可以使用Charm Down
3.8.6

现在,如何获取IMEI?看来我们没有被劝阻的选择。苹果不允许这样做。DeviceService提供了一个
UUID
,它足以拥有一个标识符。