Back to project page android_network_discovery.
The source code is released under:
GNU General Public License
If you think the Android project android_network_discovery listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package info.lamatricexiste.network; /*from w w w. j a va 2s . c om*/ import java.util.UUID; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.text.format.Formatter; import android.util.Log; public class NetworkChange extends BroadcastReceiver { public static String mTypeName = "Unknown"; public static String ssid, bssid, IP_Address; public static int link_speed, ip, rssi; public DatabaseHelper db; private WifiInfo currentWifi; private NetworkInfo info, mWifi; private WifiManager mainWifi; public static String scan_UUID; @SuppressWarnings("deprecation") @Override public void onReceive(Context context, Intent intent) { db = new DatabaseHelper(context); //if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { ConnectivityManager networkConnectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (networkConnectivity.getActiveNetworkInfo() != null && networkConnectivity.getActiveNetworkInfo().isAvailable() && networkConnectivity.getActiveNetworkInfo().isConnected()) { UUID scan = UUID.randomUUID(); scan_UUID = scan.toString(); Log.d("UUID", scan_UUID); info = networkConnectivity.getActiveNetworkInfo(); mWifi = networkConnectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI); mainWifi = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); currentWifi = mainWifi.getConnectionInfo(); mTypeName = info.getTypeName(); //WiFi or Mobile connectivity co = new connectivity(); db.createConnectiviy(co); //Do the following only if it is a WiFi connection if (mWifi.isAvailable()) { ssid = currentWifi.getSSID(); link_speed = currentWifi.getLinkSpeed(); rssi = currentWifi.getRssi(); ip = currentWifi.getIpAddress(); IP_Address = Formatter.formatIpAddress(ip); bssid = currentWifi.getBSSID(); wifiinfo wi = new wifiinfo(); Log.e("WifiInfo", "Executed"); db.createWifi(wi); db.close(); } } else { db.close(); Log.e("ERROR", "NetworkInfo returned NULL"); } // } else { // Log.e("INTENT ERROR", "intent.getAction() may be NULL"); // } } }