本文整理汇总了Java中android.net.wifi.WifiInfo.getSSID方法的典型用法代码示例。如果您正苦于以下问题:Java WifiInfo.getSSID方法的具体用法?Java WifiInfo.getSSID怎么用?Java WifiInfo.getSSID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.wifi.WifiInfo
的用法示例。
在下文中一共展示了WifiInfo.getSSID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWifiSSID
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
/**
* 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 "";
}
示例2: getWifiName
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
public String getWifiName(Context context) {
WifiManager manager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (manager.isWifiEnabled()) {
WifiInfo wifiInfo = manager.getConnectionInfo();
if (wifiInfo != null) {
NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
return wifiInfo.getSSID();
}
}
}
return null;
}
示例3: getConnectedSSID
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
/**
* This method retrieves the SSID for the currently connected network
*
* @param callbackContext A Cordova callback context
* @return true if SSID found, false if not.
*/
private boolean getConnectedSSID(CallbackContext callbackContext){
if(!wifiManager.isWifiEnabled()){
callbackContext.error("Wifi is disabled");
return false;
}
WifiInfo info = wifiManager.getConnectionInfo();
if(info == null){
callbackContext.error("Unable to read wifi info");
return false;
}
String ssid = info.getSSID();
if(ssid.isEmpty()) {
ssid = info.getBSSID();
}
if(ssid.isEmpty()){
callbackContext.error("SSID is empty");
return false;
}
callbackContext.success(ssid);
return true;
}
示例4: getCurrentSSID
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
public static String getCurrentSSID(Context context) throws Exception {
try {
WifiManager wifiManager = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getSSID();
} catch (Exception e) {
throw new Exception("目前WIFI連線名稱讀取時發生錯誤");
}
}
示例5: checkConnectedToDesiredWifi
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
/** Detect you are connected to a specific network. */
private boolean checkConnectedToDesiredWifi() {
boolean connected = false;
WifiManager wifiManager =
(WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifi = wifiManager.getConnectionInfo();
if (wifi != null) {
// get current router Mac address
String ssid = wifi.getSSID();
if(mSSID != null){
connected = mSSID.equals(ssid);
}
Log.d(mTAG, "IP: " + NetworkUtils.getIPV4Address(mContext));
}
return connected;
}
示例6: onReceive
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
@TargetApi(23)
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences preferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
String homeNetwork = preferences.getString("ssid", "HackZurich2017");
String action = intent.getAction();
if (action.equals("android.net.conn.CONNECTIVITY_CHANGE")) {
WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if(wifiMgr.isWifiEnabled()){
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
String name = wifiInfo.getSSID();
Container container = Container.instance();
container.addObserver(new PositionService(context));
if(name.equals(homeNetwork)){
container.stopTimer();
DBHelper helper = new DBHelper(context, DBHelper.DB_NAME, null, DBHelper.currentVersion);
helper.insertRoute(container.getRoute());
// reset Route
container.setRoute(new Route());
}else{
container.startTimer();
}
}
}
}
示例7: getWifiSSID
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
@ReactMethod
public void getWifiSSID(Callback callback){
String SSID;
Context context = this.getReactApplicationContext();
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(networkInfo != null && networkInfo.isConnected()){
WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
SSID = wifiInfo.getSSID();
if(SSID.startsWith("\"") && SSID.endsWith("\""))
SSID = SSID.substring(1, SSID.length()-1);
callback.invoke(null, SSID);
}
else{
callback.invoke("Error: unable to retrieve SSID.", null);
}
}
示例8: getConnectWifiSsid
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
/**
* 获取当前连接wifi的名称
*
* @return
*/
public static String getConnectWifiSsid(Context context) {
if (isWifiConnected(context)) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getSSID();
}
return null;
}
示例9: getWifiSSID
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
String getWifiSSID() {
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 "";
}
示例10: getWifiName
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
public static String getWifiName(Context context) {
if(context == null)
return null;
WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifiMgr.getConnectionInfo();
String wifiId = info != null ? info.getSSID() : null;
if(!TextUtils.isEmpty(wifiId)) {
wifiId = wifiId.replace("\"","");
}
return wifiId;
}
示例11: updateWifiInfo
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
private void updateWifiInfo() {
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
wifiSsid = wifiInfo.getSSID();
wifiBssid = wifiInfo.getBSSID();
}
示例12: getCurrentWifiSSID
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
public static String getCurrentWifiSSID(Context context) {
String ssid = "";
if (context != null) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
ssid = wifiInfo.getSSID();
if (ssid.substring(0, 1).equals("\"") && ssid.substring(ssid.length() - 1).equals("\"")) {
ssid = ssid.substring(1, ssid.length() - 1);
}
}
return ssid;
}
示例13: b
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
private static String b(Context context) {
WifiInfo connectionInfo = ((WifiManager) context.getSystemService("wifi")).getConnectionInfo();
if (connectionInfo != null) {
return connectionInfo.getSSID();
}
return "-1";
}
示例14: getWifiSSID
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
public static String getWifiSSID(Context context)
{
Context applicationContext = context.getApplicationContext();
WifiManager wifiManager = (WifiManager) applicationContext.getSystemService (applicationContext.WIFI_SERVICE);
WifiInfo info = wifiManager.getConnectionInfo();
if(info == null)
{
return "";
}
return info.getSSID();
}
示例15: onReceive
import android.net.wifi.WifiInfo; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String wifiName = wifiInfo.getSSID(); //获取的是带引号的如"Young"
if(TextUtils.isEmpty(wifiName)) return;
wifiName = wifiName.split("\"")[1]; //去引号
// Log.e(tag, "连接到WIFI " + wifiName);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
for (int i = 0; i < aims.length;i++){
if(wifiName.equalsIgnoreCase(aims[i])){
// Log.e(tag, "登陆~ " + wifiName);
Toast.makeText(context.getApplicationContext(), "登陆 "+aims[i], Toast.LENGTH_SHORT).show();
SharedPreferences sp = context.getSharedPreferences(MainActivity.PREFERENCES_NAME, Activity.MODE_PRIVATE);
String str_acc = sp.getString("account", "");
String str_psw = sp.getString("password", "");
if(TextUtils.isEmpty(str_acc)||TextUtils.isEmpty(str_psw)){
Toast.makeText(context.getApplicationContext(), "账号或密码为空", Toast.LENGTH_SHORT).show();
return;
}
DrcomAdmin drcomAdmin = DrcomAdmin.getInstance();
drcomAdmin.initAccountInfo(str_acc, str_psw);
drcomAdmin.login();
break;
}
}
// 当前WIFI名称
}
}
}