Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Unified Diff: net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java

Issue 2081493002: Obtain WiFi SSID on Android using Android APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
diff --git a/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java b/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
index fb33e23c9757cfe2591d11bd287ec1d0469aba71..125db7e3ce5dc58508da3c6cf1459300d015e9a5 100644
--- a/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
+++ b/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
@@ -7,8 +7,11 @@ package org.chromium.net;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
import android.security.KeyChain;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -229,4 +232,27 @@ class AndroidNetworkLibrary {
if (networkInfo == null) return false; // No active network.
return networkInfo.isRoaming();
}
+
+ /**
+ * Gets the SSID of the currently associated WiFi access point if there is one. Otherwise,
+ * returns empty string.
+ */
+ @CalledByNative
+ public static String getWifiSSID(Context context) {
+ if (context == null) {
+ return "";
+ }
+ final Intent intent = context.registerReceiver(
+ null, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
+ if (intent != null) {
+ final WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
+ if (wifiInfo != null) {
+ final String ssid = wifiInfo.getSSID();
+ if (ssid != null) {
+ return ssid;
+ }
+ }
+ }
+ return "";
+ }
}
« no previous file with comments | « no previous file | net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698