回答編集履歴
2
追記
test
CHANGED
@@ -1,3 +1,37 @@
|
|
1
1
|
MyIntentService.classでapi26以上は5秒以内に「startForeground(1, notification);」で、通知を出さないと異常終了する仕様です。フォアグラウンドサービスだよと通知エリアで常駐していることをアピールする必要があります。
|
2
2
|
|
3
|
+
以下のようになります。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```java
|
8
|
+
|
9
|
+
Notification notification = new Notification.Builder(context, channelId)
|
10
|
+
|
11
|
+
.setContentTitle(title)
|
12
|
+
|
13
|
+
// androidアイコン
|
14
|
+
|
15
|
+
.setSmallIcon(R.mipmap.sb_a)
|
16
|
+
|
17
|
+
.setContentText(getString(R.string.notify_summary))
|
18
|
+
|
19
|
+
.setAutoCancel(true)
|
20
|
+
|
21
|
+
.setContentIntent(pendingIntent)
|
22
|
+
|
23
|
+
.setWhen(System.currentTimeMillis())
|
24
|
+
|
25
|
+
.build();
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
// startForeground
|
30
|
+
|
31
|
+
startForeground(1, notification);
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
|
3
37
|
また、api28以上はマニフェストでもフォアグラウンドサービスがある宣言が必要です。
|
1
誤字
test
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
MyIntentService.classでapi26以上は5秒以内に「startForeground(1, notification);」で、通知を出さないと異常終了する
|
1
|
+
MyIntentService.classでapi26以上は5秒以内に「startForeground(1, notification);」で、通知を出さないと異常終了する仕様です。フォアグラウンドサービスだよと通知エリアで常駐していることをアピールする必要があります。
|
2
2
|
|
3
3
|
また、api28以上はマニフェストでもフォアグラウンドサービスがある宣言が必要です。
|