I have been working around with Android app using JavaFx (using JavaFxPorts and Gluon-Mobile ).
I have used ConnectivityService.class to check Whether the device to connected to Network.
But,the next Thing I have to do is Turn On/Off the Device's Wifi Programmatically.
How do I Implement this using Gluon-mobile API's.

- 473
- 4
- 16
-
You can't, android won't let programs modify wifi on/off state, the best you can do is tell the user to enable it. – Zharf Mar 13 '17 at 14:00
-
Actually,You can bro .Then how shareit works! – guru_007 Mar 13 '17 at 14:04
-
huh, apparently so, seems like a terrible idea though, but there's some answers on SO about it http://stackoverflow.com/a/3931094/857853 ... you just need to figure out how to translate that into gluon-mobile... – Zharf Mar 13 '17 at 14:21
-
http://stackoverflow.com/questions/37972698/how-to-access-native-android-services-from-a-gluon-mobile-app – Zharf Mar 13 '17 at 14:25
-
thanks @Zharf I'll check this out! – guru_007 Mar 13 '17 at 14:30
2 Answers
So. To get access to the FXActivity (via FXActivity.getActivity()
) you will need to update your Gradle file just slightly.
Here is how my file looks like
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.**.*'
]
}
}
The takeaway is, that I needed to include the dependencies androidCompile files("$System.env.ANDROID_HOME/**")
, otherwise my Eclipse installation wasn't able to access the Android stuff. :-/
And the dependencies, you need to access the FXActivity, are:
compile 'org.javafxports:jfxdvk:8.60.9'
androidRuntime 'org.javafxports:jfxdvk:8.60.9'
To learn about the lastest versions for jfxdvk (JavaFX Dalvik), I check the following pages, from time to time
https://bitbucket.org/javafxports/javafxmobile-plugin - here you can see, the stuff, the javafxmobile-plugin
depends on.
http://nexus.gluonhq.com/nexus/content/repositories/releases and http://nexus.gluonhq.com/nexus/content/repositories/releases - to find out, what the lastest version of the Charm Down library is (mine in the Gradle file is a bit dated already).
I hope, that helps.
Regards, Daniel

- 1,131
- 2
- 12
- 28
-
2To simply check all your dependencies for updates you can use this plugin: [link](https://github.com/ben-manes/gradle-versions-plugin) – jns Jul 21 '17 at 13:40
Hi am not familiar with gluon but if your using java You can use this method:
In the Manifest file add the following permissions:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
you can then check if WiFi is enabled through a Boolean Like this:
boolean wifiEnabled = wifiManager.isWifiEnabled()
and finaly can change state through:
WifiManager wifiManager = (WifiManager)
`this.getSystemService(Context.WIFI_SERVICE);`
wifiManager.setWifiEnabled(true);
wifiManager.setWifiEnabled(false);
hope this helps

- 736
- 5
- 10
-
Sorry,Bro I got this solution from [this](http://stackoverflow.com/questions/8863509/how-to-programmatically-turn-off-wifi-on-android-device#) Before.But I can't use Android API's in my project. – guru_007 Mar 13 '17 at 14:29
-
1Yes you can. Check the source code of the gluon charm down library. It would give you the idea. Anyway, you can simply add the necessary library to your dependencies and get access to the FXActivity from which you can access it. I will later try to compile a full answer, if you like. – dzim May 14 '17 at 15:20
-
you got any idea about [this](https://stackoverflow.com/questions/45197207/schedule-a-task-in-android-using-alarm-service-service-in-gluon-mobile) @dzim – guru_007 Jul 21 '17 at 03:57
-
1
-
Okay ,@dzim but ,i really need help on [this](https://stackoverflow.com/questions/45197207/schedule-a-task-in-android-using-alarm-service-service-in-gluon-mobile) one. – guru_007 Jul 21 '17 at 10:43