android-wifi

Listening WIFI state

こ雲淡風輕ζ 提交于 2019-11-28 12:26:48
I want to set listener to listen on wireless state,can anyone help me with my code import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; ... TelephonyManager wTelephonyManager; ... wTelephonyManager=(TelephonyManager)getSystemService(Context.WIFI_SERVICE); wTelephonyManager.listen(new PhoneL(),PhoneStateListener.LISTEN_DATA_CONNECTION_STATE); connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); //here is the event that i use that i want to listen for wifi change, and the above code is all in onCreate{} class PhoneL extends

Wifi scan results broadcast receiver not working

吃可爱长大的小学妹 提交于 2019-11-28 12:21:31
I have written a simple broadcast receiver to show a toast message when wifi scan is completed. Nothing is showing. Here is my code: package com.wifi; import java.util.List; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; import android.widget.Toast; public class wifiReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context,"Scan completed", Toast.LENGTH_LONG).show(); } } Here is the manifest file:

Android M: Unable to remove WIFI AP programmatically

人盡茶涼 提交于 2019-11-28 12:06:39
In Android M: I am using below code to remove current connected WIFI AP. void RemoveConnectedNetwork(){ int ID=_wifiManager.getConnectionInfo().getNetworkId(); Log.d("test", "network id = ["+ID+"]"); boolen ret =_wifiManager.removeNetwork(ID); Log.d("test", "removeNetwork return ="+ret); _wifiManager.saveConfiguration(); } but RemoveConnectedNetwork() always returns false . Although this API was working well in previous releases. Any solution that can be achieved on this using any other API in Android M? Thanks. Megha There are some changes in the Wifi Manager in Android 6.0. Any Wi-Fi

Detect 3G or Wifi Network restoration

☆樱花仙子☆ 提交于 2019-11-28 09:22:10
Is it possible to implement a PhoneStateListener(or any other mechanism) to detect when either the 3G or Wifi network connection is restored ? I see both LISTEN_DATA_CONNECTION_STATE and LISTEN_DATA_ACTIVITY say (cellular) in the API's summary. Does it mean 3G only ? Thanks Zelimir Better approach would be to use android.net.ConnectivityManager class. Register the receiver and monitor broadcasts. private class ConnectionMonitor extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (!action.equals(ConnectivityManager

Android Studio - Android Emulator Wifi Connected with No Internet

旧时模样 提交于 2019-11-28 08:03:49
I have wasted a whole day trying out different solutions floating around in SO and other place mentioned to enable wifi on the android emulator but to no avail. Can anybody help me figure out how do I enable internet on my android emulator? I have Nexus 5X API 27 and target being Android 8.1 (Google Play) and Nexus 5 API P and target being Android 7.1.1. I believe there should be a way to enable internet on it or else the whole point of providing virtual wifi on the emulator seems to be waste. I am on mac OS HS 10.13.4 directly connected to my router with no proxy. I even tried deleting all

Can I turn on WiFi-Direct from code? on Android API-14 (ICS)

雨燕双飞 提交于 2019-11-28 07:39:18
I'm using the new Wi-Fi Direct API from google on Android 4.0 and in Sample code they send the User to Settings, to activate WiFi -Direct Mode. Is there a way to Start it by code??? all they offer is to listen to WIFI_P2P_STATE_CHANGED_ACTION intent, and then use this code String action = intent.getAction(); if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) { // UI update to indicate wifi p2p status. int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1); if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) { // Wifi Direct mode is enabled } else { // Wifi Direct

How to get the client device details which is connected to wifi hotspot?

有些话、适合烂在心里 提交于 2019-11-28 07:03:23
I am connecting different devices with wifi hotspot AP programatically in my android app, How can i detect the clients being connected and disconnected and to the wifi hotspot AP Programmatically ? Is there any callback event in Android API to give information regarding the connection or disconnection events of individual devices ? Thanks in advance. Unfortunately there is no public API to give information about this... But you can read /proc/net/arp file and see the clients connected to your Access Point. /proc/net/arp file have 6 fields: IP address , HW type , Flags , HW address , Mask and

android turning on wifi programmatically

你说的曾经没有我的故事 提交于 2019-11-28 07:01:49
I am trying to turn add a wifi network programmatically and to connect to that network. My code works fine if the wi-fi is already turned on. If wi-fi is off, what i see wifimanager.addtonetwork() fails and when i see the wifi settings for the phone, i can see the status as scanning If i try to connect again it works fine. Please see code below. Please help private int changeNetwork(NetworkSetting setting) { // If the SSID is empty, throw an error and return if (setting.getSsid() == null || setting.getSsid().length() == 0) { return doError(R.string.wifi_ssid_missing); } // If the network type

How To Resolve Network Host Names From IP Address

一世执手 提交于 2019-11-28 06:53:33
问题 I am working on wifi based chat engine and I was able to retrieve the list of hosts connected to current wifi network by followin this link and now got list of devices with ip addresses but i need host name from the ip address and tried following InetAddress inetAddr; try { inetAddr = InetAddress.getByName(host.hostname); String hostname = inetAddr.getHostName(); String canonicalHostname = inetAddr.getCanonicalHostName(); holder.computerName.setText("Canonical : "+host.hostname); } catch

WifiManager.getScanResults() - clarifications (automatic scans, sleep etc)

爱⌒轻易说出口 提交于 2019-11-28 06:40:50
问题 I would like some clarifications on the behavior of WifiManager.getScanResults() , namely : When wireless is enabled Does android scan for access points on a fixed interval ? Can one query/change the interval ? Can one query the time of the last scan ? For a discussion see this answer What happens when the wireless radio is turned off (sleeps) - while wifi is still enabled - will getScanResults() go on returning the last scan results ? How would one know if it's time for startScan() ? When