/
PushReceiver.java
78 lines (61 loc) · 2.39 KB
/
PushReceiver.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
69
70
71
72
73
74
75
76
77
78
package com.lokesh.CDVpushyMe.plugin;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class PushReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
//-----------------------------
// Create a test notification
//
// (Use deprecated notification
// API for demonstration purposes,
// to avoid having to import
// the Android Support Library)
//-----------------------------
String notificationTitle = "Pushy";
String notificationDesc = "Test notification";
//-----------------------------
// Attempt to grab the message
// property from the payload
//
// We will be sending the following
// test push notification:
//
// {"message":"Hello World!"}
//-----------------------------
if ( intent.getStringExtra("message") != null )
{
notificationDesc = intent.getStringExtra("message");
}
//-----------------------------
// Create a test notification
//-----------------------------
Notification notification = new Notification(android.R.drawable.ic_dialog_info, notificationDesc, System.currentTimeMillis());
//-----------------------------
// Sound + vibrate + light
//-----------------------------
notification.defaults = Notification.DEFAULT_ALL;
//-----------------------------
// Dismisses when pressed
//-----------------------------
notification.flags = Notification.FLAG_AUTO_CANCEL;
//-----------------------------
// Create pending intent
// without a real intent
//-----------------------------
notification.setLatestEventInfo(context, notificationTitle, notificationDesc, null);
//-----------------------------
// Get notification manager
//-----------------------------
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//-----------------------------
// Show the notification
//-----------------------------
mNotificationManager.notify(0, notification);
}
}