尝试使用胶子访问GPS,但应用程序意外关闭



我一直在试图知道我的GPS状态是否已启用,如果没有,它将启用并给我位置坐标。但是每当我启动应用程序并单击按钮以获取坐标时,该应用程序都会意外关闭。

我的代码如下:

button.setOnAction(e->{
        PositionService positionService = Services.get(PositionService.class).orElseThrow(() -> new RuntimeException("PositionService not available."));
        positionService.positionProperty().addListener((obs, ov, nv) -> MobileApplication.getInstance().showMessage("Latest known GPS coordinates from device: " + nv.getLatitude() + ", " + nv.getLongitude()));
    }); 

我在Gluon Mobile的文档中找到了代码。

这是我的build.gradle文件。

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.3.10'
    }
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}
mainClassName = 'com.gluonapplication.test.GluonTestApplication'
dependencies {
    compile 'com.gluonhq:charm:4.4.1'
    compile 'com.gluonhq:charm-down-common:2.0.0';
    desktopRuntime 'com.gluonhq:charm-down-desktop:2.0.0';
    androidRuntime 'com.gluonhq:charm-down-android:2.0.0';
    iosRuntime 'com.gluonhq:charm-down-ios:2.0.0';
    compile group: 'com.gluonhq', name: 'charm-down-plugin-position', 
    version: '3.7.0'
}
jfxmobile {
    downConfig {
        version = '3.7.0'
        // Do not edit the line below. Use Gluon Mobile Settings in your 
project context menu instead
        plugins 'display', 'lifecycle', 'statusbar', 'storage', 'position'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
        androidSdk = 'C:/Users/Mainul/AppData/Local/Android/Sdk'
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'com.gluonhq.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
}

注意:我还在AndroidManifest.xml文件中添加了位置权限。

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

您正在混合 Charm Down 的新旧依赖项。

dependencies {
    compile 'com.gluonhq:charm:4.4.1'
    // (1)
    compile 'com.gluonhq:charm-down-common:2.0.0';
    desktopRuntime 'com.gluonhq:charm-down-desktop:2.0.0';
    androidRuntime 'com.gluonhq:charm-down-android:2.0.0';
    iosRuntime 'com.gluonhq:charm-down-ios:2.0.0';
    // (2)
    compile group: 'com.gluonhq', name: 'charm-down-plugin-position', version: '3.7.0'
}

对于初学者来说,最新的Charm Down版本是3.7.0,因此不再需要(1(中的所有"2.0.0"依赖项。

此外,downConfig设法添加所需的超级按钮依赖项,因此您无需在 dependencies {} 、(2( 中包含它们中的任何一个。

只需从 (1( 和 (2( 中删除它们:

dependencies {
    compile 'com.gluonhq:charm:4.4.1'
} 

清理并再次部署。

最新更新