質問編集履歴

2

タイトルの変更

2021/04/11 03:36

投稿

0504
0504

スコア0

test CHANGED
@@ -1 +1 @@
1
- 指定時刻通知をしたい
1
+ getSerializableExtraがnullなる
test CHANGED
File without changes

1

タイトルの変更と内容の修正

2021/04/11 03:36

投稿

0504
0504

スコア0

test CHANGED
@@ -1 +1 @@
1
- broadcastReceiverで受け取っintentからextrasが取り出せな
1
+ 指定時刻に通知をしたい
test CHANGED
@@ -1,20 +1,48 @@
1
- broadcastReceiverで受け取ったintentからextrasが取り出せせん
1
+ AlarmManagerをつかて指定時刻に通知をしいと考えてい
2
2
 
3
3
 
4
4
 
5
- intentの中身をみたところ
5
+ 通知の内容については下のようにインテントにputExtra関数でつけ、onReceive側で取り出すということ考えています
6
+
7
+
6
8
 
7
9
  ```
8
10
 
11
+ val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
12
+
9
- D/hoge hoge: Intent { flg=0x14 cmp=com.example.tannitorerukun/.notification.AttendanceNotificationReceiver (has extras) }
13
+ val intent = Intent(context, AttendanceNotificationReceiver::class.java)
14
+
15
+ intent.putExtra(course_data, data)
16
+
17
+
18
+
19
+ val calendar = dateIdToTime(data.dateId)
20
+
21
+
22
+
23
+ val pendingIntent = PendingIntent.getBroadcast(
24
+
25
+ context, data.dateId, intent, PendingIntent.FLAG_UPDATE_CURRENT
26
+
27
+ )
28
+
29
+
30
+
31
+ alarmManager.setExact(
32
+
33
+ AlarmManager.RTC,
34
+
35
+ calendar.timeInMillis,
36
+
37
+ pendingIntent
38
+
39
+ )
10
40
 
11
41
  ```
12
42
 
13
- このようになっておりintentの中にextrasはあるようです
14
43
 
15
44
 
16
-
17
- ですが取り出そうとすると以下のようエラーが発生しま
45
+ ですがレシーバー側で取り出そうとしたころ、以下のようエラーが発生しました
18
46
 
19
47
 
20
48
 
@@ -24,9 +52,35 @@
24
52
 
25
53
  Process: com.example.hoge_hoge, PID: 11015
26
54
 
27
- java.lang.RuntimeException: Unable to start receiver com.example.hoge_hoge.notification.AttendanceNotificationReceiver: java.lang.NullPointerException: null cannot be cast to non-null type com.example.tannitorerukun.data.CourseLog
55
+ java.lang.RuntimeException: Unable to start receiver com.example.hoge_hoge.notification.AttendanceNotificationReceiver: java.lang.NullPointerException: null cannot be cast to non-null type com.example.hoge_hoge.data.CourseLog
28
56
 
29
57
  ```
58
+
59
+
60
+
61
+
62
+
63
+ toString関数を使い、intentの中身をみたところ以下のようになっておりextrasはついているようです
64
+
65
+ ```
66
+
67
+ D/hoge hoge: Intent { flg=0x14 cmp=com.example.tannitorerukun/.notification.AttendanceNotificationReceiver (has extras) }
68
+
69
+ ```
70
+
71
+
72
+
73
+
74
+
75
+ どなたか解決方法をご存じの方がいらっしゃいましたら教えていただきたいです
76
+
77
+ また、そもそもやりかたが間違っている、もっといい方法があるなどございましたらご指摘いただけると嬉しいです
78
+
79
+
80
+
81
+ よろしくお願いします
82
+
83
+
30
84
 
31
85
 
32
86