Created
June 2, 2020 20:38
-
-
Save MrCrambo/28a2ead1a489700f1e4cea57ece6484e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final WifiNetworkSuggestion suggestion1 = | |
new WifiNetworkSuggestion.Builder() | |
.setSsid("navigine_test_1") | |
.build() | |
final WifiNetworkSuggestion suggestion2 = | |
new WifiNetworkSuggestion.Builder() | |
.setSsid("navigine_test_2") | |
.setWpa2Passphrase("navigine_test_2_pass") | |
.build() | |
final List<WifiNetworkSuggestion> suggestionsList = | |
new ArrayList<WifiNetworkSuggestion> {{ | |
add(suggestion1); | |
add(suggestion2); | |
}}; | |
final WifiManager wifiManager = | |
(WifiManager) context.getSystemService(Context.WIFI_SERVICE); | |
final int status = wifiManager.addNetworkSuggestions(suggestionsList); | |
if (status != WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS) { | |
// do error handling here… | |
} | |
final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
if (!intent.getAction().equals( | |
WifiManager.ACTION_WIFI_NETWORK_SUGGESTION_POST_CONNECTION)) { | |
return; | |
} | |
// do post connect processing here... | |
} | |
}; | |
context.registerReceiver(broadcastReceiver, intentFilter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment