我一直在使用 JavaFx 处理 Android 应用程序(使用 JavaFxPorts 和 Gluon-Mobile )。
我用过ConnectivityService.class检查设备是否连接到网络。
但是,我要做的下一件事是以编程方式打开/关闭设备的 Wifi。
如何使用 Gluon-mobile API 实现此功能。
最佳答案
所以。要访问 FXActivity(通过 FXActivity.getActivity()
),您需要稍微更新您的 Gradle 文件。
这是我的文件的样子
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.5'
}
}
apply plugin: 'org.javafxports.jfxmobile'
compileJava.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'ch.cnlab.disentis.Main'
// preloaderClassName = 'ch.cnlab.disentis.Preloader'
dependencies {
compile 'com.gluonhq:charm:4.3.1'
compile 'org.controlsfx:controlsfx:8.40.12'
compileNoRetrolambda 'com.airhacks:afterburner.mfx:1.6.2'
compile 'de.jensd:fontawesomefx-commons:8.15'
compile 'de.jensd:fontawesomefx-fontawesome:4.7.0-5'
compile 'de.jensd:fontawesomefx-materialdesignfont:1.7.22-4'
compile 'de.jensd:fontawesomefx-materialicons:2.2.0-5'
compile 'de.jensd:fontawesomefx-controls:8.15'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.4'
compile 'commons-codec:commons-codec:1.10'
androidCompile files("$System.env.ANDROID_HOME/platforms/android-22/android.jar")
androidCompile files("$System.env.ANDROID_HOME/extras/android/support/v4/android-support-v4.jar")
compile 'org.javafxports:jfxdvk:8.60.9'
androidRuntime 'org.javafxports:jfxdvk:8.60.9'
}
jfxmobile {
downConfig {
plugins 'display', 'lifecycle', 'storage', 'orientation', 'settings', 'browser', 'ble'
}
android {
manifest = 'src/android/AndroidManifest.xml'
compileSdkVersion = 22
minSdkVersion = 19
targetSdkVersion = 22
dexOptions {
javaMaxHeapSize '2g'
}
packagingOptions {
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/NOTICE'
pickFirst 'license/LICENSE.txt'
}
signingConfig {
storeFile file('signing/android/my-release-key.keystore')
File propsFile = file('signing/android/keystore.properties');
if (propsFile.exists()) {
Properties props = new Properties();
props.load(new FileInputStream(propsFile))
storePassword props.getProperty('RELEASE_STORE_PASSWORD')
keyAlias props.getProperty('RELEASE_KEY_ALIAS')
keyPassword props.getProperty('RELEASE_KEY_PASSWORD')
}
}
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'de.jensd.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'javax.xml.**.*',
'org.glassfish.json.**.*',
'com.airhacks.**.*',
'okio.**.*',
'okhttp3.**.*',
'com.fasterxml.**.*',
'ch.cnlab.disentis.**.*'
]
}
}
要点是,我需要包含依赖项 androidCompile files("$System.env.ANDROID_HOME/**")
,否则我的 Eclipse 安装无法访问 Android 内容。 :-/
访问 FXActivity 所需的依赖项是:
compile 'org.javafxports:jfxdvk:8.60.9'
androidRuntime 'org.javafxports:jfxdvk:8.60.9'
要了解 jfxdvk (JavaFX Dalvik) 的最新版本,我会不时查看以下页面
https://bitbucket.org/javafxports/javafxmobile-plugin - 在这里您可以看到 javafxmobile-plugin
所依赖的东西。
http://nexus.gluonhq.com/nexus/content/repositories/releases和 http://nexus.gluonhq.com/nexus/content/repositories/releases - 了解 Charm Down 库的最新版本是什么(Gradle 文件中的我的版本已经有点过时了)。
我希望这会有所帮助。
问候,丹尼尔
关于android - 使用 gluon-mobile API 以编程方式打开/关闭 Android 中的 Wifi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42765461/