我想在我的 wifi 开启时开始我的活动,以便在 WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION 时调用我的活动。它将与 2.3(姜饼)三星水龙头一起正常工作,但相同的程序在 3.1(蜂窝)三星水龙头中无法正常工作。为什么会在这里发生这种类型的问题是我的孔代码:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.util.Log;
/**
* A BroadcastReceiver that listens for updates for the
* ExampleAppWidgetProvider. This BroadcastReceiver starts off disabled, and we
* only enable it when there is a widget instance created, in order to only
* receive notifications when we need them.
*/
public class WIFIBroadcastReceiver extends BroadcastReceiver {
public static String packageName = "com.example.wifi";
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
if (intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,
false)) {
Log.d(packageName, "WIFI Connected");
if (context != null) {
Intent ssIntent = new Intent(context,
com.example.wifi.Activity.class);
ssIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(ssIntent);
}
} else {
Log.d(packageName, "WIFI Connection was Lost");
}
}
}
}