Fixed API lvl < 17 quotation mark issue and wifi deactivation on CompoundButton isChecked==true
This commit is contained in:
parent
221659c745
commit
f7097d0cb5
3 changed files with 25 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="tueroeffner" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
|
@ -9,6 +9,7 @@
|
|||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
|
||||
|
@ -24,6 +25,7 @@
|
|||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.content.Intent;
|
|||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
@ -34,6 +35,12 @@ public class DerivBroadcastReceiver extends BroadcastReceiver {
|
|||
if (nwInfo != null && nwInfo.isConnectedOrConnecting()) {
|
||||
String ssid = wifiInfo.getSSID();
|
||||
|
||||
|
||||
// Build.VERSION.SDK_INT is incompatible with device API lvl < 4 use String.toInteger(Build.VERSION.SDK) or maybe find some other way ^_^
|
||||
if (Build.VERSION.SDK_INT > 17){
|
||||
targetSSID.replace("\"", "");
|
||||
}
|
||||
|
||||
if (ssid.equals(targetSSID)){
|
||||
buttonActivator((Activity) context, true);
|
||||
Toast.makeText(context, context.getString(R.string.wlan_connected), Toast.LENGTH_SHORT).show();
|
||||
|
|
|
@ -48,7 +48,7 @@ import java.util.List;
|
|||
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
|
||||
final static String networkSSID = "KrautSpace";
|
||||
static String networkSSID = "KrautSpace";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -60,6 +60,7 @@ public class MainActivity extends ActionBarActivity {
|
|||
.commit();
|
||||
}
|
||||
|
||||
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) ;
|
||||
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
|
@ -132,7 +133,16 @@ public class MainActivity extends ActionBarActivity {
|
|||
Context context = rootView.getContext();
|
||||
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
|
||||
if (isChecked) {
|
||||
WifiConfiguration conf = new WifiConfiguration();
|
||||
|
||||
WifiConfiguration wifiConfig = new WifiConfiguration();
|
||||
wifiConfig.SSID = String.format("\"%s\"", networkSSID);
|
||||
|
||||
int netId = wifiManager.addNetwork(wifiConfig);
|
||||
wifiManager.disconnect();
|
||||
wifiManager.enableNetwork(netId, true);
|
||||
wifiManager.reconnect();
|
||||
|
||||
/*WifiConfiguration conf = new WifiConfiguration();
|
||||
conf.SSID = networkSSID;
|
||||
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
||||
int retval = wifiManager.addNetwork(conf);
|
||||
|
@ -147,10 +157,10 @@ public class MainActivity extends ActionBarActivity {
|
|||
}
|
||||
}
|
||||
wifiManager.disconnect();
|
||||
wifiManager.reconnect();
|
||||
wifiManager.reconnect();*/
|
||||
Toast.makeText(buttonView.getContext(), getString(R.string.wlan_activated), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
|
||||
/*List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
|
||||
for( WifiConfiguration i : list ) {
|
||||
if(i.SSID != null && i.SSID.equals(networkSSID)) {
|
||||
wifiManager.removeNetwork(i.networkId);
|
||||
|
@ -159,7 +169,7 @@ public class MainActivity extends ActionBarActivity {
|
|||
}
|
||||
}
|
||||
wifiManager.disconnect();
|
||||
wifiManager.reconnect();
|
||||
wifiManager.reconnect();*/
|
||||
Toast.makeText(buttonView.getContext(), getString(R.string.wlan_deactivated), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue