Wifi Available , Connected And Required User Authentication - java

I am working on an application where I need detect if wifi avilable and connected also authenticated in my android device .
I know how to detect this this using ConnectivityManager and NetworkInfo.It working fine but problem facing where wifi available and connected when we type URL for any site it goes 1st on another proxy site for user name and password to access the internet.I search around to detail my question and got a site of GSM provider http://www.du.ae/en/mobile/wifi-1 ,they are providing Wifi also,When I am in train it showing available network (Wifi) ,When i type any site it 1st it ask me user name and password for Authentication to access the internet. can I detect using code that user is connected and authenticated with Wifi ?
Waiting for appreciable answer to solve my this issue .
Thanks . .

NetworkInfo info = ((ConnectivityManager) mContext
.getSystemService(Context.CONNECTIVITY_SERVICE))
.getActiveNetworkInfo();
if (info == null || !info.isConnected()) {
return false;
}
if (info.isRoaming()) {
return true;
}
sem to wifi used
ANDROID: if WiFi is enabled AND active, launch an intent

Related

Firebase Showing An Internal Error has occured. [7:]

I'm using Firebase as my cloud data in my android app. I'm using it's Firestore and Authentication feature. But when I try to signup it is showing me :
"An internal error has occurred. [7:]"
So, to solve this I came to search for the solution so I found that if I update the google_service.json file everything is going to be right. But When I updated it sometimes it is working and after some time it again shows me the same error.
I get this error while testing my app behavior when deliberately disabling my mobile internet connection and trying to login to my app using firebase Auth.
Try testing your network connectivity on Activity launch and display a toast
public static boolean getConnectivityStatus(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (null != activeNetwork) {
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
return true;
if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
return true;
}
Toast.makeText(context, "No network connection!", Toast.LENGTH_SHORT).show();
return false;
}
I had same problem with authentication via Firebase in my RN iOS project. After some research I found out that "Email/Password" Sign In/Up option was disabled. So I just turned it on. Hope it will help someone with similar issue.
https://i.stack.imgur.com/zoQ6g.png
Please check the internet connection of your device. I make the same mistake after internet connection enables it working.
Same error happened while I tried with network connection off and firebase authentication with email and password. for example,
FirebaseAuth.getInstance().signInWithEmailAndPassword(email, password)... { ... }
If network connection is on, then it works fine.
make sure you run your emulator like this in vs Code
flutter emulators --launch Nexus_6_API_29 -dns-8.8.8.8
this will solve your problem

How to get the Bluetooth device model name?

I have an android application related to bluetooth and I have a question. How can I find out which device is connected to a smartphone? I need to know the device model, I can get the device name, but the user can change it, for example “MEIZU EP51” == >> “My favorite headphones”. I need to get the device model or ID, for example, I connected the Meizu EP51 headphones and I need the phone to recognize exactly the model of these headphones. In the Android documentation, I did not find it, maybe I did not read carefully, I would be grateful for the answer.
You can get the connected ble devices by Bluetooth Manager like this,
BluetoothManager bluetoothManager = (BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE);
List<BluetoothDevice> devices = bluetoothManager.getConnectedDevices(BluetoothProfile.GATT);
As i have Mi Band 3 i can see this connected device over it. But as it is BLE device so it is visible to me but not sure about other devices.
By BluetoothDevice object you can get device name and address. Try it.

Android wifimanager enable network seems to enable wrong network

I have made an android app which on startup gets the current wifi network and connects to a different one. At least that is what it is supposed to do:
wifiInfo = wifiManager.getConnectionInfo();
OldNetworkID = wifiInfo.getNetworkId(); //save current network
WDTNetworkID = wifiManager.addNetwork(wificonfiguration); //add new network
wifiManager.disconnect();
wifiManager.enableNetwork(WDTNetworkID, true); //enable new network and disable all others
wifiManager.reconnect();
When I debug I can see wificonfiguration contains the right SSID (the SSID of the new network).
After addNetwork() I see that wifiManager.getConfiguredNetworks() contains this new network with the right SSID and the same networkID as WDTNetworkID. At this point the network is enabled.
But after enableNetwork() instead of WDTNetworkID enabled and the rest disabled I see that OldNetworkID is enabled and the rest is disabled.
Am I doing something wrong?
I have added a picture of a couple of watches while debugging.
You can see here that the old network is enabled and the rest is disabled.
The problem here is that the device the app is running on is android 5.1.1.
As it states in the documentation of enableNetwork():
Note: If an application's target SDK version is LOLLIPOP or newer, network communication may not use Wi-Fi even if Wi-Fi is connected; traffic may instead be sent through another network, such as cellular data, Bluetooth tethering, or Ethernet. For example, traffic will never use a Wi-Fi network that does not provide Internet access (e.g. a wireless printer), if another network that does offer Internet access (e.g. cellular data) is available. Applications that need to ensure that their network traffic uses Wi-Fi should use APIs such as bindSocket(java.net.Socket), openConnection(java.net.URL), or bindProcessToNetwork(Network) to do so.
You just need add this line to your code. i had same problem, adding this line help me.conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
//After sleep a little milliseconds then check exist connection with this code:
try {
Thread.sleep(3000);
Toast.makeText(MyActivity.this, "You are connected to " +
mainWifimanagerObject.getConnectionInfo().getSSID(), Toast.LENGTH_LONG).show();
}
catch (InterruptedException e) {e.printStackTrace();}

How to send input values in android to d1mini wifi controller through wifi?

I'm working on a app which will create hotspot when it opens, after opening the app user have to send user name and password to connected deceives , let say if i have a d1mini wifi controller which is connected to hotspot, i need to send the input values to d1mini, i tried wifip2p and socket programming but both wont work!
please any one help me how to send input values to hardware devices through wifi!

No longer able to connect to a Wi-Fi network since Android Nougat

I have an app that I use to connect to WiFi network that doesn't have connection to the Internet. It has been working fine with versions before Nougat. Since I upgraded my phone to Nougat few weeks ago, I'm not able to connect to the same WiFi network anymore. It connected briefly and disconnected and then rolled back to the previous network that has connection to the Internet. Below is the code that was working fine before Nougat.
WifiManager manager = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
WifiConfiguration selectedConfig = new WifiConfiguration();
selectedConfig.SSID = ssid;
selectedConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
manager.addNetwork(selectedConfig);
List<WifiConfiguration> cofigs = manager.getConfiguredNetworks();
for( WifiConfiguration config : cofigs)
{
if(config.SSID != null && config.SSID.equals(selectedConfig.SSID))
{
manager.disconnect();
manager.enableNetwork(config.networkId, true);
break;
}
}
In the past, setting true in manager.enableNetwork(config.networkId, true) seemed to let the connection stay on with the network that doesn't have connection to the internet. However, since Nougat, this doesn't seem to work anymore.
Does anyone know what's going on and how to make it work?
Thanks.
the boolean parameter from the enableNetwork method is to block the other networks.
Actually, there is no way for you to tell the device to connect to certain network, the only thing that you can do is to block the other networks and that way, the only option that the device has to connect is the one that you didn't disable (the one with the id on the 1st parameter).
I would recommend you to try and check what is returned from the addNetwork and check this google issue Google issue .
If that doesn't solve your problem, check if you are scanning somewhere else. If you scan for the available networks, your device will enable the other networks, so the others won't be disabled anymore and your device will connect to the one that it was in the beginning or the one that has higher priority.
Hope it helped

Categories