質問編集履歴

1

サンプルコードを追加

2015/06/04 04:56

投稿

takukill
takukill

スコア23

test CHANGED
File without changes
test CHANGED
@@ -12,17 +12,65 @@
12
12
 
13
13
  ```lang-<java>
14
14
 
15
+ import android.bluetooth.BluetoothAdapter;
16
+
17
+ import android.content.BroadcastReceiver;
18
+
19
+ import android.content.Context;
20
+
21
+ import android.content.Intent;
22
+
23
+ import android.net.wifi.WifiManager;
24
+
25
+ import android.util.Log;
26
+
27
+
28
+
29
+ public class TestBroadcastReceiver extends BroadcastReceiver {
30
+
31
+
32
+
33
+ private String TAG = "test";
34
+
35
+
36
+
37
+ @Override
38
+
39
+ public void onReceive(Context context, Intent intent) {
40
+
41
+ String action = intent.getAction();
42
+
43
+
44
+
15
45
  if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
16
46
 
17
47
  WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
18
48
 
19
49
  if (wm.getWifiState() == WifiManager.WIFI_STATE_ENABLED || wm.getWifiState() == WifiManager.WIFI_STATE_DISABLED) {
20
50
 
21
- Log.v("","wifi:"wm.getWifiState());
51
+ Log.v(TAG, "WIFI:" + wm.getWifiState());
22
52
 
23
53
  }
24
54
 
25
55
  }
56
+
57
+
58
+
59
+ if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { // BlueTooth
60
+
61
+ BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
62
+
63
+ if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON || mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
64
+
65
+ Log.v(TAG, "ブルー:" + mBluetoothAdapter.getState());
66
+
67
+ }
68
+
69
+ }
70
+
71
+ }
72
+
73
+ }
26
74
 
27
75
  ```
28
76