@@ -55,7 +55,8 @@ public class HostNotificationProfile extends NotificationProfile {
5555 /**
5656 * Notification Flag.
5757 */
58- private static final String ACTON_NOTIFICATION = "org.deviceconnect.android.intent.action.notifiy" ;
58+ private static final String ACTON_CLICK_NOTIFICATION = "org.deviceconnect.android.intent.action.click.notifiy" ;
59+ private static final String ACTON_DELETE_NOTIFICATION = "org.deviceconnect.android.intent.action.delete.notifiy" ;
5960
6061 /** ランダムシード. */
6162 private final Random mRandom = new Random ();
@@ -71,8 +72,10 @@ public String getAttribute() {
7172 public boolean onRequest (final Intent request , final Intent response ) {
7273 if (mNotificationStatusReceiver == null ) {
7374 mNotificationStatusReceiver = new NotificationStatusReceiver ();
74- getContext ().getApplicationContext ().registerReceiver (mNotificationStatusReceiver ,
75- new IntentFilter (ACTON_NOTIFICATION ));
75+ IntentFilter filter = new IntentFilter ();
76+ filter .addAction (ACTON_CLICK_NOTIFICATION );
77+ filter .addAction (ACTON_DELETE_NOTIFICATION );
78+ getContext ().getApplicationContext ().registerReceiver (mNotificationStatusReceiver , filter );
7679 }
7780 String serviceId = getServiceID (request );
7881 NotificationType type = getType (request );
@@ -120,12 +123,20 @@ public boolean onRequest(final Intent request, final Intent response) {
120123 setResult (response , IntentDConnectMessage .RESULT_OK );
121124 } else {
122125 // Build intent for notification content
123- Intent notifyIntent = new Intent (ACTON_NOTIFICATION );
124- notifyIntent .putExtra ("notificationId" , notifyId );
125- notifyIntent .putExtra ("serviceId" , serviceId );
126+ Intent notifyClickIntent = new Intent (ACTON_CLICK_NOTIFICATION );
127+ notifyClickIntent .putExtra ("notificationId" , notifyId );
128+ notifyClickIntent .putExtra ("serviceId" , serviceId );
129+
130+ PendingIntent pendingClickIntent = PendingIntent .getBroadcast (getContext (),
131+ notifyId , notifyClickIntent , PendingIntent .FLAG_UPDATE_CURRENT );
132+
133+ Intent notifyDeleteIntent = new Intent (ACTON_DELETE_NOTIFICATION );
134+ notifyDeleteIntent .putExtra ("notificationId" , notifyId );
135+ notifyDeleteIntent .putExtra ("serviceId" , serviceId );
136+
137+ PendingIntent pendingDeleteIntent = PendingIntent .getBroadcast (getContext (),
138+ notifyId , notifyDeleteIntent , PendingIntent .FLAG_UPDATE_CURRENT );
126139
127- PendingIntent mPendingIntent = PendingIntent .getBroadcast (getContext (),
128- notifyId , notifyIntent , PendingIntent .FLAG_UPDATE_CURRENT );
129140
130141 Notification notification ;
131142 // Get an instance of the NotificationManager service
@@ -137,15 +148,17 @@ public boolean onRequest(final Intent request, final Intent response) {
137148 .setSmallIcon (iconType )
138149 .setContentTitle ("" + title )
139150 .setContentText (encodeBody )
140- .setContentIntent (mPendingIntent );
151+ .setContentIntent (pendingClickIntent )
152+ .setDeleteIntent (pendingDeleteIntent );
141153 notification = notificationBuilder .build ();
142154 } else {
143155 Notification .Builder notificationBuilder =
144156 new Notification .Builder (getContext ())
145157 .setSmallIcon (Icon .createWithResource (getContext (), iconType ))
146158 .setContentTitle ("" + title )
147159 .setContentText (encodeBody )
148- .setContentIntent (mPendingIntent );
160+ .setContentIntent (pendingClickIntent )
161+ .setDeleteIntent (pendingDeleteIntent );
149162 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
150163 String channelId = getContext ().getResources ().getString (R .string .host_notification_channel_id );
151164 NotificationChannel channel = new NotificationChannel (
@@ -235,7 +248,7 @@ public String getAttribute() {
235248 @ Override
236249 public boolean onRequest (final Intent request , final Intent response ) {
237250 mNotificationStatusReceiver = new NotificationStatusReceiver ();
238- IntentFilter intentFilter = new IntentFilter (ACTON_NOTIFICATION );
251+ IntentFilter intentFilter = new IntentFilter (ACTON_CLICK_NOTIFICATION );
239252 getContext ().registerReceiver (mNotificationStatusReceiver , intentFilter );
240253
241254 // イベントの登録
@@ -259,6 +272,10 @@ public String getAttribute() {
259272
260273 @ Override
261274 public boolean onRequest (final Intent request , final Intent response ) {
275+ mNotificationStatusReceiver = new NotificationStatusReceiver ();
276+ IntentFilter intentFilter = new IntentFilter (ACTON_DELETE_NOTIFICATION );
277+ getContext ().registerReceiver (mNotificationStatusReceiver , intentFilter );
278+
262279 // イベントの登録
263280 EventError error = EventManager .INSTANCE .addEvent (request );
264281
@@ -412,6 +429,19 @@ private class NotificationStatusReceiver extends BroadcastReceiver {
412429
413430 @ Override
414431 public void onReceive (final Context context , final Intent intent ) {
432+ String profile ;
433+ if (intent .getAction () == null ) {
434+ return ;
435+ }
436+ // Intent#getAction()によってイベントプロファイル名を決める。
437+ // 他のアクション名であれば処理をしない。
438+ if (intent .getAction ().equals (ACTON_CLICK_NOTIFICATION )) {
439+ profile = HostNotificationProfile .ATTRIBUTE_ON_CLICK ;
440+ } else if (intent .getAction ().equals (ACTON_DELETE_NOTIFICATION )) {
441+ profile = HostNotificationProfile .ATTRIBUTE_ON_CLOSE ;
442+ } else {
443+ return ;
444+ }
415445 // クリティカルセクション(バッテリーステータスの状態更新etc)にmutexロックを掛ける。
416446 synchronized (this ) {
417447
@@ -422,7 +452,7 @@ public void onReceive(final Context context, final Intent intent) {
422452 mServiceId ,
423453 HostNotificationProfile .PROFILE_NAME ,
424454 null ,
425- HostNotificationProfile . ATTRIBUTE_ON_CLICK );
455+ profile );
426456
427457 for (int i = 0 ; i < events .size (); i ++) {
428458 Event event = events .get (i );
0 commit comments