質問編集履歴
1
onMessageReceivedファイルを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,3 +29,119 @@
|
|
29
29
|
|
30
30
|
|
31
31
|
ご回答よろしくお願いいたします。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
下記コードはonMessageReceivedが書いてあるファイルです。
|
38
|
+
|
39
|
+
※細かいところは省略しています。
|
40
|
+
|
41
|
+
MyFirebaseMessagingService.java
|
42
|
+
|
43
|
+
```Java
|
44
|
+
|
45
|
+
public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
private static final String TAG = "MyFirebaseMsgService";
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
@Override
|
54
|
+
|
55
|
+
public void onNewToken(String token) {
|
56
|
+
|
57
|
+
…省略
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
@Override
|
64
|
+
|
65
|
+
public void onMessageReceived(RemoteMessage remoteMessage) {
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
Log.d(TAG,"プッシュ通知が来た");
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
if (remoteMessage != null) {
|
74
|
+
|
75
|
+
// 通知メッセージ
|
76
|
+
|
77
|
+
RemoteMessage.Notification notification = remoteMessage.getNotification();
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
if (notification != null) {
|
82
|
+
|
83
|
+
// 通知メッセージを処理
|
84
|
+
|
85
|
+
Log.d(TAG,notification.getTitle());
|
86
|
+
|
87
|
+
Log.d(TAG,notification.getBody());
|
88
|
+
|
89
|
+
Log.d(TAG,notification.getClickAction());
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
String imageUrl;
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
if(notification.getImageUrl() != null){
|
98
|
+
|
99
|
+
Log.d(TAG,notification.getImageUrl().toString());
|
100
|
+
|
101
|
+
imageUrl = notification.getImageUrl().toString();
|
102
|
+
|
103
|
+
}else{
|
104
|
+
|
105
|
+
Log.d(TAG,"なにも入っていません");
|
106
|
+
|
107
|
+
imageUrl = "";
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
//プッシュ通知をデータベースに入れ込み
|
114
|
+
|
115
|
+
PushList pushList = new PushList();
|
116
|
+
|
117
|
+
PushListInsertAsync pushListInsertAsync = new PushListInsertAsync(notification.getTitle(),notification.getBody(),dateTime,notification.getClickAction(),1,0,imageUrl,getApplicationContext(),pushList);
|
118
|
+
|
119
|
+
pushListInsertAsync.execute();
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
//フォアグランド用にタイトル・本文・チャンネルを作成
|
128
|
+
|
129
|
+
String title = notification.getTitle();
|
130
|
+
|
131
|
+
String body = notification.getBody();
|
132
|
+
|
133
|
+
String channel = notification.getChannelId();
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
//Push通知表示用メソッド呼び出し
|
138
|
+
|
139
|
+
sendNotification(title,body,channel);
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
```
|