首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Gluon获取设备信息问题

使用Gluon获取设备信息问题
EN

Stack Overflow用户
提问于 2019-01-30 19:04:52
回答 1查看 118关注 0票数 0

我计划获取手机的IMEI,以便在我的应用程序中生成二维码或条形码。我在提问前已经检查过问题了。此外,我还查看了gluon移动文档以获取更多详细信息。但这似乎并没有解决我的问题。ispresent()中的代码块永远不会被执行。以下是我的代码

代码语言:javascript
复制
Services.get(DeviceService.class).ifPresent(deviceService -> {
            label.setText("Modeld: "+"Test" );
            label.setText("Model: "+ deviceService.getModel()+"\nSerial: "+ deviceService.getSerial());
        });

Build.gradles

代码语言:javascript
复制
  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中显示任何错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-30 19:25:34

如果你检查你的构建文件中的downConfig块,你会注意到你的应用程序正在使用的插件列表,或Charm Down服务:

代码语言:javascript
复制
jfxmobile {
     downConfig {
        version = '3.8.5'
        plugins 'display', 'lifecycle', 'statusbar', 'storage'
     }
...
}

jfxmobile正在为每个插件添加核心工件及其平台实现:

代码语言:javascript
复制
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 )中具有传递依赖关系,但仅在核心构件中,因此您将添加:

代码语言:javascript
复制
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()将为空。

在这种情况下,您需要做的就是将device插件添加到列表中:

您的构建将具有:

代码语言:javascript
复制
jfxmobile {
     downConfig {
        version = '3.8.6'
        plugins 'device', 'display', 'lifecycle', 'statusbar', 'storage'
     }
...
}

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54439106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档