いつもお世話になっております。
wifiとbluetoothの切り替わったタイミングを取得したいのですが、
端末によって、2回来たり1回来たりしていた
なぜか苦戦しています。
取得方法は以下の方法を使用しています。
lang
1import android.bluetooth.BluetoothAdapter; 2import android.content.BroadcastReceiver; 3import android.content.Context; 4import android.content.Intent; 5import android.net.wifi.WifiManager; 6import android.util.Log; 7 8public class TestBroadcastReceiver extends BroadcastReceiver { 9 10 private String TAG = "test"; 11 12 @Override 13 public void onReceive(Context context, Intent intent) { 14 String action = intent.getAction(); 15 16 if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { 17 WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); 18 if (wm.getWifiState() == WifiManager.WIFI_STATE_ENABLED || wm.getWifiState() == WifiManager.WIFI_STATE_DISABLED) { 19 Log.v(TAG, "WIFI:" + wm.getWifiState()); 20 } 21 } 22 23 if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { // BlueTooth 24 BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 25 if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON || mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) { 26 Log.v(TAG, "ブルー:" + mBluetoothAdapter.getState()); 27 } 28 } 29 } 30}
上記方法だと、
1.wifiが変更されたらtrue
2.wifiが接続した、又は、接続を切断したタイミングでtrue
となるはずなのですが、なぜかログが二回出力されることがあります。
回避方法、若しくは、2回来る理由など知っている方がいたら教えてほしいです。
お忙しい中申し訳ありません。よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/06/10 01:46
2015/06/10 15:32