Android: Using tiwlan0 to determine wireless connected status for Droid - android

I want to be able to check the status of Droid's wireless and I was hoping that by reading /sys/class/net/tiwlan0/wireless/status I could find out if it was actually connected or not. I already know that I can check if my wireless is enabled/disabled but I want my app to notify the user if the wireless gets disconnected.
However, the Droid I have is not rooted and I do not have permission from the owner to root it and I need to know the type of the value (e.g. long, boolean, byte) before I can proceed.
Any help or suggestions about other ways I can go about this would be greatly appreciated!
Thanks

You should just be able to listen to the SUPPLICANT_STATE_CHANGED_ACTION broadcast. It will notify you of a change (scanning, association, disconnection, etc.) in the form of a SupplicantState object inside an extra.

Install terminal emulater, run it and type the following at the command line: "ifconfig -a". Read the IP address listed under tiwlan0.

Related

Read Preferred Network Type Setting

I am trying to read the Preferred network type setting from the device. But nowhere android API's are available.
Use case:
Trying to read the Preferred network type and connected network type so that if the device has LTE enabled and the user is forcefully switched back to the lower network(3G,2G); then there should be a notification sent to the user.
I have checked the system setting code, But it's deprecated.
Settings.Secure.getString(getApplicationContext().getContentResolver(),
Settings.System.NETWORK_PREFERENCE);
Is there any alternate way to read the system secured settings(By reflection?).
And Also is it possible to write back the setting with the user permission?
Help is much appreciated.
I think the right code is:
Settings.Global.getString(context.getContentResolver(),Settings.Global.NETWORK_PREFERENCE)

android 6.0.1 force wifi connection with no internet access

this has many similar questions (google for: "no internet access detected. won't automatically reconnect." or: android force wifi connection programmatically).
i thought i had a answer here, but it stopped working after installing 6.0.1 updates (i have may 1 security patches).
seems like this is a behaviour change.
i have some 2013 nexus 7's with 6.0.1 that run a kiosk type app and want to connect programmatically to a specific wireless network that has no internet connection. each tablet has a unique static ip address of the form: 192.168.0.xx. i use the normal java socket constructors and check to see if the interface is up using: NetworkInterface.getNetworkInterfaces().
a manual connection has been made. sometimes there is a dialog that asks whether or not you want to always connect. i always check yes.
but the wifi says: "no internet access detected. won't automatically reconnect" after the router cycles power.
doing a disconnect, enable, reconnect does not work. at best it gets: ip6-localhost/::1.
has anyone had any luck using a request object, or bindProcessToNetwork?
edit: related.
edit: the problem seems to be with: CAPTIVE_PORTAL_DETECTION_ENABLED - this string seems to be defined in the source:
public static final String
CAPTIVE_PORTAL_DETECTION_ENABLED = "captive_portal_detection_enabled";
...
MOVED_TO_GLOBAL.add(Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED);
but throws" android.provider.Settings$SettingNotFoundException: captive_portal_detection_enabled when used explicitly and is not visible to android studio.
also, doing a settings list global does not contain the constant.
edit doing a adb shell settings put global captive_portal_detection_enabled 0 does seem to work, but this can not be done in the field when the router cycles power. this value seems to persist when the tablet cycles power. and now this value shows up in a settings list global. also, using the raw string: Settings.Global.getInt(getContentResolver(),"captive_portal_detection_enabled"); now returns 0.
edit: looks like setting it requires: android.permission.WRITE_SECURE_SETTINGS, but of course this fails when put into the manifest since we are not a system app.
edit: trying to exec the shell command throws: java.lang.SecurityException, so it looks like you need to issue the command from adb :(
thanks
Could you try and set the global setting captive_portal_detection_enabled to 0 (false).
What's actually happening is that by default, everytime you connect to a wifi, the FW will test against a server (typically google) to see if it's a captive wifi (needs login). So if your wifi is not connected to google, this check will fail. After that, the device knows that wifi has no internet connection and simply will not autoconnect to it.
Setting this setting to 0, will avoid this check.
Programatically Settings.Global.putInt(getContentResolver(), Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED, 0);
You can do it through adb for testing purposes:
adb shell settings put global captive_portal_detection_enabled 0
And retrieve it's value like this:
adb shell settings list global | grep "captive"
IMHO this is not very nice thing to do, since you are changing a setting for the user and many FWs don't provide even an advanced setting to enable/disable this by the user itself. (Google doesn't). But maybe it suits your needs.
Hope it helps!
A non-root solution which is a kind of hack tech. :P
Reboot phone, connect to the non-Internet Wifi;
Go to Settings and create a new user;
Continue, continue, and continue until you see "Checking connection";
As soon as you see "checking connection", switch off your phone;
Switch on your phone again, you will be in "Owner" user, keep it;
Toggle Wifi, and the exclamation mark should disappear quickly :)
Remove that new user or just leave it there;
I don't know why, but it works...

router administrator change Wi-Fi channel programmatically with android

i would like if my question is possible or not.
Well every channel has a specefic frequency 1 à 13(2,4GHz), 36 to 64(5GHz) and 100 to 165(5GHz).
for example :
channel number 1 : 2412GHz ;channel number 2 : 2417GHz.
Well when we enter to the router interface from the localhost address ,we can easely choose a channel.
What i would like to do is to change the channel programmatically (from my android app ) .
I have an idea ,but i don't know if it's feaseble or not ,is to simulate the router web interface and do the same work that it doeas with android.
if someone has an idea please help me
PS: 'm the router adminsrator
Thank you
I think that is possible you connect to your router by SSH, and then, you change the configuration, and restart wireless, but, then, you will lost connection when channel changes.
However, I dont know if your router allow this operation with SSH
I have another idea:
With wireshark, see the HTTP packet sent between your PC and your router, when you does Login, and when you save configuration. If you understand them, maybe you make a new packet in your phone.
(sorry my English)
You can try to configure the router with SSH.

Enable 3G and WiFi Simultaneously

Does anyone know if its possible (programatically) to enable both 3G and WiFi to be used simultaneously, both receiving and sending packets?
I have seen various other questions on here, but with the Tethering ability inside Android now, I was wondering if this is a possibility? This has to be on a standard/stock device, and no modifications via root to the OS.
Thanks
Adam
I don't believe it is, as soon as wifi is turned on, 3g will automatically disconnect. As far as I know there is no way round it.
The only way you can achieve this is by using a APN name with the HttpConnection. This is possible in Java ME, Please visit this answer, however i have never tried it.
You need to check for the active connection, if not active first one the switch to the next connection.
public void shutup(){
SuDroid cmd = new SuDroid();
cmd.sh.runWaitFor("svc wifi enable");
cmd.sh.runWaitFor("svc data enable");
cmd.sh.runWaitFor("svc data prefer");
}
Using SuDroido

Set Data roaming on/off

How could I programmatically set data roaming on/off in my android application ?
Apologies in advance for reopening a dead post but I have managed to achieve it by calling this executable:
su -c settings put global data_roaming0 1
Also to get the roaming setting for first SIM card:
su -c settings get global data_roaming0
If your app is signatureOrSystem/Privileged app (app resides in /system/priv-app) and your have valid android.permission.WRITE_SECURE_SETTINGS permission in system/etc/permissions. Then you can do it as below.
Enable :
Settings.Global.putInt(context.getContentResolver(), Settings.Global.DATA_ROAMING, 1)
Disable :
Settings.Global.putInt(context.getContentResolver(), Settings.Global.DATA_ROAMING, 0)
I hope that it's not possible to turn on data roaming programmatically as this would be a serious security issue from my point of view ...
Data roaming (i.e. UMTS data transfer via a foreign network) may result in a huge bill from your network provider - at least in europe.
If data roaming is currently on, then I think you can manipulate the Access Points Names in order to make it appear that a data service isn't available. See this post which also links to apndroid. You could browse their source and see the approach they have taken.
If data roaming has been set to off by the user, then this approach won't work. Though you could prompt users to turn it on as part of your install/setup process, which is the route apndroid take.
apndroid also provide an API for changing these kind of settings, which might be more convenient than reimplementing the same functionality.
On rooted devices when using su to enable data roaming, on multi sim devices the data roaming setting is sim specific.
So you need to get the sim number that is active for data calls
sim_num = settings get global multi_sim_data_call
and use this in the data_roaming + sim_num setting. EG sim_num 3
settings get global data_roaming3
if this is null then not multi sim device and use data_roaming otherwise use
settings put global data_roaming3
I was able to enable data roaming on my dual sim Motorola G8 without the need to root it via ADB. I'm posting here the procedure, because the phone has a bug that prevents data roaming from being enabled normally.
You need a computer and to install ADB installed
Enable developer mode and USB debugging in your phone
Connect the phone to the computer via USB and accept the debugging connection.
Start an "adb shell", be sure that it is correctly connected to your phone.
Issue the command
settings put global data_roaming1 1
to enable data roaming for SIM card 1, or
settings put global data_roaming2 1
to enable it for SIM 2
Note: if you do not have the USB cable, this can be done via wifi, but the pairing process is a bit complicated and version dependent.
If you do not have a computer, it may be possible to run the commands directly on the phone using a "local adb" app (there are a few on the play store), but I have not tested any.

Categories

Resources