1
1
package com .plugin .gcm ;
2
2
3
- import java .util .List ;
4
-
5
- import com .google .android .gcm .GCMBaseIntentService ;
6
3
import org .json .JSONException ;
7
4
import org .json .JSONObject ;
8
5
9
6
import android .annotation .SuppressLint ;
10
- import android .app .ActivityManager ;
11
- import android .app .ActivityManager .RunningTaskInfo ;
12
7
import android .app .Notification ;
13
8
import android .app .NotificationManager ;
14
9
import android .app .PendingIntent ;
18
13
import android .support .v4 .app .NotificationCompat ;
19
14
import android .util .Log ;
20
15
16
+ import com .google .android .gcm .GCMBaseIntentService ;
17
+
21
18
@ SuppressLint ("NewApi" )
22
19
public class GCMIntentService extends GCMBaseIntentService {
23
20
24
- public static final int NOTIFICATION_ID = 237 ;
25
21
private static final String TAG = "GCMIntentService" ;
26
22
27
23
public GCMIntentService () {
@@ -94,7 +90,8 @@ public void createNotification(Context context, Bundle extras)
94
90
.setWhen (System .currentTimeMillis ())
95
91
.setContentTitle (extras .getString ("title" ))
96
92
.setTicker (extras .getString ("title" ))
97
- .setContentIntent (contentIntent );
93
+ .setContentIntent (contentIntent )
94
+ .setAutoCancel (true );
98
95
99
96
String message = extras .getString ("message" );
100
97
if (message != null ) {
@@ -108,13 +105,19 @@ public void createNotification(Context context, Bundle extras)
108
105
mBuilder .setNumber (Integer .parseInt (msgcnt ));
109
106
}
110
107
111
- mNotificationManager .notify ((String ) appName , NOTIFICATION_ID , mBuilder .build ());
112
- }
113
-
114
- public static void cancelNotification (Context context )
115
- {
116
- NotificationManager mNotificationManager = (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
117
- mNotificationManager .cancel ((String )getAppName (context ), NOTIFICATION_ID );
108
+ int notId = 0 ;
109
+
110
+ try {
111
+ notId = Integer .parseInt (extras .getString ("notId" ));
112
+ }
113
+ catch (NumberFormatException e ) {
114
+ Log .e (TAG , "Number format exception - Error parsing Notification ID: " + e .getMessage ());
115
+ }
116
+ catch (Exception e ) {
117
+ Log .e (TAG , "Number format exception - Error parsing Notification ID" + e .getMessage ());
118
+ }
119
+
120
+ mNotificationManager .notify ((String ) appName , notId , mBuilder .build ());
118
121
}
119
122
120
123
private static String getAppName (Context context )
0 commit comments