質問編集履歴
1
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,6 +14,8 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
+
|
18
|
+
|
17
19
|
```Java
|
18
20
|
|
19
21
|
public class MainActivity extends ActionBarActivity {
|
@@ -34,28 +36,80 @@
|
|
34
36
|
|
35
37
|
context = getApplicationContext();
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
//通知許可設定
|
40
|
-
|
41
|
-
Button btn1 = (Button) findViewById(R.id.button1);
|
42
|
-
|
43
|
-
btn1.setOnClickListener(new View.OnClickListener() {
|
44
|
-
|
45
|
-
public void onClick(View v) {
|
46
|
-
|
47
|
-
moveNotificationAccessSettingMenu();
|
48
|
-
|
49
|
-
}
|
50
|
-
|
51
|
-
});
|
52
|
-
|
53
39
|
}
|
54
40
|
|
55
41
|
}
|
56
42
|
|
57
43
|
```
|
58
44
|
|
45
|
+
```java
|
46
|
+
|
47
|
+
public class NotificationService extends NotificationListenerService {
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
private final String NOTIFICATION_TEXT = "NOTIFICATION_TEXT"; //ブロードキャスト用
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
@Override
|
56
|
+
|
57
|
+
public void onCreate() {
|
58
|
+
|
59
|
+
super.onCreate();
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
@Override
|
66
|
+
|
67
|
+
public void onDestroy() {
|
68
|
+
|
69
|
+
super.onDestroy();
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
/**
|
76
|
+
|
77
|
+
* 通知発生時のリスナー(システム側で許可設定が必要)
|
78
|
+
|
79
|
+
*/
|
80
|
+
|
81
|
+
@Override
|
82
|
+
|
83
|
+
public void onNotificationPosted(StatusBarNotification sbn) {
|
84
|
+
|
85
|
+
Log.v("NotificationService", "onNotificationPosted");
|
86
|
+
|
87
|
+
startBroadCast(text);
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
/**
|
94
|
+
|
95
|
+
* ブロードキャストの送信
|
96
|
+
|
97
|
+
*/
|
98
|
+
|
99
|
+
private void startBroadCast(String str){
|
100
|
+
|
101
|
+
Intent intent = new Intent(NOTIFICATION_SERVICE);
|
102
|
+
|
103
|
+
intent.putExtra(NOTIFICATION_TEXT, str);
|
104
|
+
|
105
|
+
sendBroadcast(intent);
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
```
|
112
|
+
|
59
113
|
```Java
|
60
114
|
|
61
115
|
public class TestReceiver extends BroadcastReceiver {
|