本文整理匯總了Java中android.net.wifi.SupplicantState類的典型用法代碼示例。如果您正苦於以下問題:Java SupplicantState類的具體用法?Java SupplicantState怎麽用?Java SupplicantState使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SupplicantState類屬於android.net.wifi包,在下文中一共展示了SupplicantState類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onReceive
import android.net.wifi.SupplicantState; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
_logger.Debug("_wifiStateReceiver onReceive");
String action = intent.getAction();
if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION.equals(action)) {
SupplicantState state = intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE);
if ((SupplicantState.isValidState(state) && state == SupplicantState.COMPLETED)) {
_logger.Debug("Successfully connected WIFI completed!");
if (_sendDataController.GetSelectedServerIp() == null) {
SearchForServer();
}
}
} else {
_logger.Warn(String.format("Action is %s", action));
}
}
示例2: createWifiInfo
import android.net.wifi.SupplicantState; //導入依賴的package包/類
private static WifiInfo createWifiInfo() throws Exception {
WifiInfo info = mirror.android.net.wifi.WifiInfo.ctor.newInstance();
IPInfo ip = getIPInfo();
InetAddress address = (ip != null ? ip.addr : null);
mirror.android.net.wifi.WifiInfo.mNetworkId.set(info, 1);
mirror.android.net.wifi.WifiInfo.mSupplicantState.set(info, SupplicantState.COMPLETED);
mirror.android.net.wifi.WifiInfo.mBSSID.set(info, VASettings.Wifi.BSSID);
mirror.android.net.wifi.WifiInfo.mMacAddress.set(info, VASettings.Wifi.MAC);
mirror.android.net.wifi.WifiInfo.mIpAddress.set(info, address);
mirror.android.net.wifi.WifiInfo.mLinkSpeed.set(info, 65);
if (Build.VERSION.SDK_INT >= 21) {
mirror.android.net.wifi.WifiInfo.mFrequency.set(info, 5000); // MHz
}
mirror.android.net.wifi.WifiInfo.mRssi.set(info, 200); // MAX_RSSI
if (mirror.android.net.wifi.WifiInfo.mWifiSsid != null) {
mirror.android.net.wifi.WifiInfo.mWifiSsid.set(info, WifiSsid.createFromAsciiEncoded.call(VASettings.Wifi.SSID));
} else {
mirror.android.net.wifi.WifiInfo.mSSID.set(info, VASettings.Wifi.SSID);
}
return info;
}
示例3: isAlreadyConnected
import android.net.wifi.SupplicantState; //導入依賴的package包/類
/**
* Checks if the user is already connected to a wifi access point.
* @return True, if connected.
*/
public boolean isAlreadyConnected() {
// get an instance of the wifi-manager and information of the current access point
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
SupplicantState supplicantState = wifiInfo.getSupplicantState();
// does the supplicant wifi-cli have a completed-state?
if(SupplicantState.COMPLETED.equals(supplicantState)) {
// completed state, connected to access point
Log.d(LOG_TAG, "Already connected to an access point");
return true;
}
else {
return false;
}
}
示例4: onReceive
import android.net.wifi.SupplicantState; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
handleWifiStateChanged(intent.getIntExtra(
WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN));
} else if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION.equals(action)) {
if (!mConnected.get()) {
handleStateChanged(WifiInfo.getDetailedStateOf((SupplicantState)
intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE)));
}
} else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
WifiManager.EXTRA_NETWORK_INFO);
mConnected.set(info.isConnected());
handleStateChanged(info.getDetailedState());
}
}
示例5: supplicantStateChanges
import android.net.wifi.SupplicantState; //導入依賴的package包/類
@SuppressWarnings("ResourceType") @Test //
public void supplicantStateChanges() throws IllegalAccessException, InstantiationException {
Application application = RuntimeEnvironment.application;
TestSubscriber<SupplicantStateChangedEvent> o = new TestSubscriber<>();
RxWifiManager.supplicantStateChanges(application).subscribe(o);
o.assertValues();
Intent intent1 = new Intent(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION) //
.putExtra(EXTRA_NEW_STATE, (Parcelable) SupplicantState.INACTIVE)
.putExtra(EXTRA_SUPPLICANT_ERROR, ERROR_AUTHENTICATING);
application.sendBroadcast(intent1);
SupplicantStateChangedEvent event1 =
SupplicantStateChangedEvent.create(SupplicantState.INACTIVE, ERROR_AUTHENTICATING);
o.assertValues(event1);
Intent intent2 = new Intent(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION) //
.putExtra(EXTRA_NEW_STATE, (Parcelable) SupplicantState.ASSOCIATING)
.putExtra(EXTRA_SUPPLICANT_ERROR, -1);
application.sendBroadcast(intent2);
SupplicantStateChangedEvent event2 =
SupplicantStateChangedEvent.create(SupplicantState.ASSOCIATING, -1);
o.assertValues(event1, event2);
}
示例6: updateTrust
import android.net.wifi.SupplicantState; //導入依賴的package包/類
private void updateTrust(String trustedSsid) {
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo == null) {
return;
}
if (wifiInfo.getSSID() == null) {
return;
}
if (wifiInfo.getSupplicantState() == SupplicantState.COMPLETED) {
if (trustedSsid.equals(wifiInfo.getSSID())) {
GhettoTrustAgent.sendGrantTrust(this, "GhettoTrustAgent", TRUST_DURATION_30SECS,
false);
}
else {
Log.d(TAG, "Found insecure SSID: " + trustedSsid);
GhettoTrustAgent.sendRevokeTrust(this);
}
} else {
Log.d(TAG, "Disconnected from Wifi: " + trustedSsid);
GhettoTrustAgent.sendRevokeTrust(this);
}
}
示例7: isAlreadyConnected
import android.net.wifi.SupplicantState; //導入依賴的package包/類
private boolean isAlreadyConnected(WifiManager wm) {
boolean alreadyConnected = false;
WifiInfo connectionInfo = wm.getConnectionInfo();
if (connectionInfo != null) {
SupplicantState supplicantState = connectionInfo.getSupplicantState();
if (supplicantState != null) {
alreadyConnected = supplicantState.equals(SupplicantState.ASSOCIATING)
|| supplicantState.equals(SupplicantState.ASSOCIATED)
|| supplicantState.equals(SupplicantState.COMPLETED)
|| supplicantState.equals(SupplicantState.FOUR_WAY_HANDSHAKE)
|| supplicantState.equals(SupplicantState.GROUP_HANDSHAKE);
}
}
return alreadyConnected;
}
示例8: execute
import android.net.wifi.SupplicantState; //導入依賴的package包/類
@Override
public void execute(Context service)
{
delegate.setInstallingState(IndicatorState.ACTIVE, 0, service.getString(R.string.if_ardrone_led_green_reset_wifi_connection));
boolean connected = false;
WifiManager mgr = (WifiManager) service.getSystemService(Context.WIFI_SERVICE);
while (!connected) {
WifiInfo info = mgr.getConnectionInfo();
SupplicantState state = info.getSupplicantState();
if (state == SupplicantState.COMPLETED ||
state == SupplicantState.DORMANT) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
break;
}
}
delegate.setInstallingState(IndicatorState.ACTIVE, 0, service.getString(R.string.if_ardrone_led_green_reset_wifi_connection));
}
示例9: onReceive
import android.net.wifi.SupplicantState; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if(BuildConfig.DEBUG) Logger.debug(TAG, "onReceive:" + action);
if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION .equals(action)) {
SupplicantState state = intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE);
if(state == SupplicantState.COMPLETED) {
final WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
if(wifiManager != null) {
WifiInfo info = wifiManager.getConnectionInfo();
if (info != null) {
mContext = context;
onWiFiConnected(info.getSSID());
}
}
}
}
}
示例10: isWifiConnected
import android.net.wifi.SupplicantState; //導入依賴的package包/類
/**
* Check whether WiFi is connected
* @param context a Context instance
* @return true if Wifi is connected
*/
// @RequiresPermission(value = Manifest.permission.ACCESS_WIFI_STATE)
public static boolean isWifiConnected(Context context) {
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifiManager == null || !wifiManager.isWifiEnabled()) return false;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo == null || wifiInfo.getNetworkId() == -1) return false;
return wifiInfo.getSupplicantState() == SupplicantState.ASSOCIATED;
}
示例11: onReceive
import android.net.wifi.SupplicantState; //導入依賴的package包/類
@Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION.equals(action)) {
SupplicantState state = intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE);
if (!(SupplicantState.isValidState(state) && state == SupplicantState.COMPLETED)) {
Logger.getInstance().Warning(TAG, "Not yet a valid connection!");
return;
}
}
new Handler().postDelayed(() -> {
BroadcastController broadcastController = new BroadcastController(context);
if (new NetworkController(context).IsHomeNetwork(SettingsController.getInstance().GetHomeSsid())) {
if (!new AndroidSystemController(context).IsServiceRunning(MainService.class)) {
Intent startMainServiceIntent = new Intent(context, MainService.class);
startMainServiceIntent.putExtra(MainService.MainServiceOnStartCommandBundle, true);
context.startService(startMainServiceIntent);
} else {
broadcastController.SendSimpleBroadcast(MainService.MainServiceStartDownloadAllBroadcast);
}
broadcastController.SendSimpleBroadcast(NetworkController.WIFIReceiverInHomeNetworkBroadcast);
} else {
TemperatureService.getInstance().CloseNotification();
WirelessSocketService.getInstance().CloseNotification();
WirelessSwitchService.getInstance().CloseNotification();
broadcastController.SendSimpleBroadcast(NetworkController.WIFIReceiverNoHomeNetworkBroadcast);
}
}, 10 * 1000);
}
示例12: serializeWifiInfo
import android.net.wifi.SupplicantState; //導入依賴的package包/類
private JSONObject serializeWifiInfo(WifiInfo data) throws JSONException {
JSONObject result = new JSONObject(mGson.toJson(data));
result.put("SSID", trimQuotationMarks(data.getSSID()));
for (SupplicantState state : SupplicantState.values()) {
if (data.getSupplicantState().equals(state)) {
result.put("SupplicantState", state.name());
}
}
return result;
}
示例13: connectNetwork
import android.net.wifi.SupplicantState; //導入依賴的package包/類
/**
* This method connects a network.
*
* @param callbackContext A Cordova callback context
* @param data JSON Array, with [0] being SSID to connect
* @return true if network connected, false if failed
*/
private boolean connectNetwork(CallbackContext callbackContext, JSONArray data) {
Log.d(TAG, "WifiWizard: connectNetwork entered.");
if(!validateData(data)) {
callbackContext.error("WifiWizard: connectNetwork invalid data");
Log.d(TAG, "WifiWizard: connectNetwork invalid data.");
return false;
}
String ssidToConnect = "";
try {
ssidToConnect = data.getString(0);
}
catch (Exception e) {
callbackContext.error(e.getMessage());
Log.d(TAG, e.getMessage());
return false;
}
int networkIdToConnect = ssidToNetworkId(ssidToConnect);
if (networkIdToConnect >= 0) {
// We disable the network before connecting, because if this was the last connection before
// a disconnect(), this will not reconnect.
wifiManager.disableNetwork(networkIdToConnect);
wifiManager.enableNetwork(networkIdToConnect, true);
SupplicantState supState;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
supState = wifiInfo.getSupplicantState();
callbackContext.success(supState.toString());
return true;
}else{
callbackContext.error("WifiWizard: cannot connect to network");
return false;
}
}
示例14: startScan
import android.net.wifi.SupplicantState; //導入依賴的package包/類
private void startScan() {
SupplicantState wifiState = remoController.getWifiState();
Log.d(TAG, "startScan: " + wifiState);
if (wifiState != SupplicantState.COMPLETED) {
changeState(State.WIFI_ERROR);
showWifiErrorDialog();
return;
} else {
changeState(State.SCAN);
remoController.startDiscovery();
deviceMap = new HashMap<String, String>();
showScanDialog();
}
}
示例15: onReceive
import android.net.wifi.SupplicantState; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION .equals(action)) {
SupplicantState state = intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE);
if (SupplicantState.isValidState(state)
&& state == SupplicantState.COMPLETED) {
mIsConnected = checkConnectedToDesiredWifi();
if(mCallback != null){
if(mIsConnected){
mCallback.onSuccess();
}
else{
mCallback.onFailed();
}
}
}
else if(SupplicantState.isValidState(state)
&& state == SupplicantState.DISCONNECTED){
Log.d(mTAG, "Wifi STA is disconnected");
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
wifiManager.reconnect();
}
}
}