Handle null WifiManager

git-svn-id: https://zxing.googlecode.com/svn/trunk@2842 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen@gmail.com 2013-07-19 15:57:03 +00:00
parent dd79103734
commit 19b5cfe06d
2 changed files with 7 additions and 1 deletions

View file

@ -19,6 +19,7 @@ package com.google.zxing.client.android.result;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.util.Log;
import android.widget.Toast;
import com.google.zxing.client.android.CaptureActivity;
@ -37,6 +38,8 @@ import com.google.zxing.client.result.WifiParsedResult;
*/
public final class WifiResultHandler extends ResultHandler {
private static final String TAG = WifiResultHandler.class.getSimpleName();
private final CaptureActivity parent;
private final AsyncTaskExecInterface taskExec;
@ -62,6 +65,10 @@ public final class WifiResultHandler extends ResultHandler {
if (index == 0) {
WifiParsedResult wifiResult = (WifiParsedResult) getResult();
WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
if (wifiManager == null) {
Log.w(TAG, "No WifiManager available from device");
return;
}
final Activity activity = getActivity();
activity.runOnUiThread(new Runnable() {
@Override

View file

@ -96,7 +96,6 @@ public final class WifiConfigManager extends AsyncTask<WifiParsedResult,Object,O
/**
* Update the network: either create a new network or modify an existing network
* @param config the new network configuration
* @return network ID of the connected network.
*/
private static void updateNetwork(WifiManager wifiManager, WifiConfiguration config) {
Integer foundNetworkID = findNetworkInExistingConfig(wifiManager, config.SSID);