-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPendingIntentService.java
68 lines (50 loc) · 2.12 KB
/
PendingIntentService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.arifulislam.tourguidepro.services;
import android.app.IntentService;
import android.app.NotificationManager;
import android.content.Intent;
import android.media.RingtoneManager;
import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;
import android.util.Log;
import com.arifulislam.tourguidepro.R;
import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.GeofencingEvent;
import java.util.ArrayList;
import java.util.List;
public class PendingIntentService extends IntentService {
private static final String TAG = "intent";
public PendingIntentService() {
super("PendingIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent event = GeofencingEvent.fromIntent(intent);
int transitionType = event.getGeofenceTransition();
List<Geofence> trigraringGeofence = event.getTriggeringGeofences();
String trasString = null;
switch (transitionType) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
trasString = "Entered ";
break;
case Geofence.GEOFENCE_TRANSITION_EXIT:
trasString = "Exited ";
break;
}
ArrayList<String> triggraingGeoffenceIDs = new ArrayList<>();
try{
for (Geofence geofence : trigraringGeofence) {
triggraingGeoffenceIDs.add(geofence.getRequestId());
}
}catch (NullPointerException e){}
String notifyString = trasString +": "+ TextUtils.join(", ",triggraingGeoffenceIDs);
Log.d(TAG, "onHandleIntent: "+notifyString);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.mipmap.ic_launcher_round);
builder.setContentTitle(notifyString);
builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (manager != null) {
manager.notify(991, builder.build());
}
}
}