├── AndroidManifest.xml
├── README
├── libs
└── android-support-v4.jar
├── res
├── drawable-hdpi
│ ├── codeversed_logo.png
│ └── ic_launcher.png
├── drawable-ldpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── layout
│ ├── main.xml
│ └── notification_custom_remote.xml
└── values
│ └── strings.xml
└── src
└── com
└── codeversed
└── example
└── Notifications
├── MainActivity.java
└── ResultActivity.java
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
13 |
14 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | This file was created by IntelliJ IDEA 12.1.4 for binding GitHub repository
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeversed/notifications/c28f65a9b98d8c20a8636e0514ee895be933c9fd/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/res/drawable-hdpi/codeversed_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeversed/notifications/c28f65a9b98d8c20a8636e0514ee895be933c9fd/res/drawable-hdpi/codeversed_logo.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeversed/notifications/c28f65a9b98d8c20a8636e0514ee895be933c9fd/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeversed/notifications/c28f65a9b98d8c20a8636e0514ee895be933c9fd/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeversed/notifications/c28f65a9b98d8c20a8636e0514ee895be933c9fd/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeversed/notifications/c28f65a9b98d8c20a8636e0514ee895be933c9fd/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
25 |
26 |
31 |
32 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/res/layout/notification_custom_remote.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
17 |
18 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Notifications
4 | Codeversed Logo
5 | Normal
6 | Big Text Style
7 | Big Picture Style
8 | Inbox Style
9 | Custom View
10 |
11 |
--------------------------------------------------------------------------------
/src/com/codeversed/example/Notifications/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.codeversed.example.Notifications;
2 |
3 | import android.app.*;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.os.AsyncTask;
9 | import android.os.Bundle;
10 | import android.support.v4.app.NotificationCompat;
11 | import android.view.View;
12 | import android.widget.RemoteViews;
13 |
14 | import java.io.IOException;
15 | import java.io.InputStream;
16 | import java.net.URL;
17 |
18 | public class MainActivity extends Activity {
19 |
20 | private final static String sample_url = "http://codeversed.com/androidifysteve.png";
21 |
22 | private final static int NORMAL = 0x00;
23 | private final static int BIG_TEXT_STYLE = 0x01;
24 | private final static int BIG_PICTURE_STYLE = 0x02;
25 | private final static int INBOX_STYLE = 0x03;
26 | private final static int CUSTOM_VIEW = 0x04;
27 |
28 | private static NotificationManager mNotificationManager;
29 |
30 | @Override
31 | public void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.main);
34 | mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
35 | }
36 |
37 | public void setNormalStyle(View view) {
38 | new CreateNotification(NORMAL).execute();
39 | }
40 |
41 | public void setBigTextStyle(View view) {
42 | new CreateNotification(BIG_TEXT_STYLE).execute();
43 | }
44 |
45 | public void setBigPictureStyle(View view) {
46 | new CreateNotification(BIG_PICTURE_STYLE).execute();
47 | }
48 |
49 | public void setInboxStyle(View view) {
50 | new CreateNotification(INBOX_STYLE).execute();
51 | }
52 |
53 | public void setCustomView(View view) {
54 | new CreateNotification(CUSTOM_VIEW).execute();
55 | }
56 |
57 | /**
58 | * Notification AsyncTask to create and return the
59 | * requested notification.
60 | *
61 | * @see CreateNotification#CreateNotification(int)
62 | */
63 | public class CreateNotification extends AsyncTask {
64 |
65 | int style = NORMAL;
66 |
67 | /**
68 | * Main constructor for AsyncTask that accepts the parameters below.
69 | *
70 | * @param style {@link #NORMAL}, {@link #BIG_TEXT_STYLE}, {@link #BIG_PICTURE_STYLE}, {@link #INBOX_STYLE}
71 | * @see #doInBackground
72 | */
73 | public CreateNotification(int style) {
74 | this.style = style;
75 | }
76 |
77 | /**
78 | * Creates the notification object.
79 | *
80 | * @see #setNormalNotification
81 | * @see #setBigTextStyleNotification
82 | * @see #setBigPictureStyleNotification
83 | * @see #setInboxStyleNotification
84 | */
85 | @Override
86 | protected Void doInBackground(Void... params) {
87 | Notification noti = new Notification();
88 |
89 | switch (style)
90 | {
91 | case NORMAL:
92 | noti = setNormalNotification();
93 | break;
94 |
95 | case BIG_TEXT_STYLE:
96 | noti = setBigTextStyleNotification();
97 | break;
98 |
99 | case BIG_PICTURE_STYLE:
100 | noti = setBigPictureStyleNotification();
101 | break;
102 |
103 | case INBOX_STYLE:
104 | noti = setInboxStyleNotification();
105 | break;
106 |
107 | case CUSTOM_VIEW:
108 | noti = setCustomViewNotification();
109 | break;
110 |
111 | }
112 |
113 | noti.defaults |= Notification.DEFAULT_LIGHTS;
114 | noti.defaults |= Notification.DEFAULT_VIBRATE;
115 | noti.defaults |= Notification.DEFAULT_SOUND;
116 |
117 | noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
118 |
119 | mNotificationManager.notify(0, noti);
120 |
121 | return null;
122 |
123 | }
124 | }
125 |
126 | /**
127 | * Normal Notification
128 | *
129 | * @return Notification
130 | * @see CreateNotification
131 | */
132 | private Notification setNormalNotification() {
133 | Bitmap remote_picture = null;
134 |
135 | try {
136 | remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
137 | } catch (IOException e) {
138 | e.printStackTrace();
139 | }
140 |
141 | // Setup an explicit intent for an ResultActivity to receive.
142 | Intent resultIntent = new Intent(this, ResultActivity.class);
143 |
144 | // TaskStackBuilder ensures that the back button follows the recommended convention for the back key.
145 | TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
146 |
147 | // Adds the back stack for the Intent (but not the Intent itself).
148 | stackBuilder.addParentStack(ResultActivity.class);
149 |
150 | // Adds the Intent that starts the Activity to the top of the stack.
151 | stackBuilder.addNextIntent(resultIntent);
152 | PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
153 |
154 | return new NotificationCompat.Builder(this)
155 | .setSmallIcon(R.drawable.ic_launcher)
156 | .setAutoCancel(true)
157 | .setLargeIcon(remote_picture)
158 | .setContentIntent(resultPendingIntent)
159 | .addAction(R.drawable.ic_launcher, "One", resultPendingIntent)
160 | .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent)
161 | .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent)
162 | .setContentTitle("Normal Notification")
163 | .setContentText("This is an example of a Normal Style.").build();
164 | }
165 |
166 | /**
167 | * Big Text Style Notification
168 | *
169 | * @return Notification
170 | * @see CreateNotification
171 | */
172 | private Notification setBigTextStyleNotification() {
173 | Bitmap remote_picture = null;
174 |
175 | // Create the style object with BigTextStyle subclass.
176 | NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle();
177 | notiStyle.setBigContentTitle("Big Text Expanded");
178 | notiStyle.setSummaryText("Nice big text.");
179 |
180 | try {
181 | remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
182 | } catch (IOException e) {
183 | e.printStackTrace();
184 | }
185 |
186 | // Add the big text to the style.
187 | CharSequence bigText = "This is an example of a large string to demo how much " +
188 | "text you can show in a 'Big Text Style' notification.";
189 | notiStyle.bigText(bigText);
190 |
191 | // Creates an explicit intent for an ResultActivity to receive.
192 | Intent resultIntent = new Intent(this, ResultActivity.class);
193 |
194 | // This ensures that the back button follows the recommended convention for the back key.
195 | TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
196 |
197 | // Adds the back stack for the Intent (but not the Intent itself).
198 | stackBuilder.addParentStack(ResultActivity.class);
199 |
200 | // Adds the Intent that starts the Activity to the top of the stack.
201 | stackBuilder.addNextIntent(resultIntent);
202 | PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
203 |
204 | return new NotificationCompat.Builder(this)
205 | .setSmallIcon(R.drawable.ic_launcher)
206 | .setAutoCancel(true)
207 | .setLargeIcon(remote_picture)
208 | .setContentIntent(resultPendingIntent)
209 | .addAction(R.drawable.ic_launcher, "One", resultPendingIntent)
210 | .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent)
211 | .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent)
212 | .setContentTitle("Big Text Normal")
213 | .setContentText("This is an example of a Big Text Style.")
214 | .setStyle(notiStyle).build();
215 | }
216 |
217 | /**
218 | * Big Picture Style Notification
219 | *
220 | * @return Notification
221 | * @see CreateNotification
222 | */
223 | private Notification setBigPictureStyleNotification() {
224 | Bitmap remote_picture = null;
225 |
226 | // Create the style object with BigPictureStyle subclass.
227 | NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
228 | notiStyle.setBigContentTitle("Big Picture Expanded");
229 | notiStyle.setSummaryText("Nice big picture.");
230 |
231 | try {
232 | remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
233 | } catch (IOException e) {
234 | e.printStackTrace();
235 | }
236 |
237 | // Add the big picture to the style.
238 | notiStyle.bigPicture(remote_picture);
239 |
240 | // Creates an explicit intent for an ResultActivity to receive.
241 | Intent resultIntent = new Intent(this, ResultActivity.class);
242 |
243 | // This ensures that the back button follows the recommended convention for the back key.
244 | TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
245 |
246 | // Adds the back stack for the Intent (but not the Intent itself).
247 | stackBuilder.addParentStack(ResultActivity.class);
248 |
249 | // Adds the Intent that starts the Activity to the top of the stack.
250 | stackBuilder.addNextIntent(resultIntent);
251 | PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
252 |
253 | return new NotificationCompat.Builder(this)
254 | .setSmallIcon(R.drawable.ic_launcher)
255 | .setAutoCancel(true)
256 | .setLargeIcon(remote_picture)
257 | .setContentIntent(resultPendingIntent)
258 | .addAction(R.drawable.ic_launcher, "One", resultPendingIntent)
259 | .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent)
260 | .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent)
261 | .setContentTitle("Big Picture Normal")
262 | .setContentText("This is an example of a Big Picture Style.")
263 | .setStyle(notiStyle).build();
264 | }
265 |
266 | /**
267 | * Inbox Style Notification
268 | *
269 | * @return Notification
270 | * @see CreateNotification
271 | */
272 | private Notification setInboxStyleNotification() {
273 | Bitmap remote_picture = null;
274 |
275 | // Create the style object with InboxStyle subclass.
276 | NotificationCompat.InboxStyle notiStyle = new NotificationCompat.InboxStyle();
277 | notiStyle.setBigContentTitle("Inbox Style Expanded");
278 |
279 | // Add the multiple lines to the style.
280 | // This is strictly for providing an example of multiple lines.
281 | for (int i=0; i < 5; i++) {
282 | notiStyle.addLine("(" + i + " of 6) Line one here.");
283 | }
284 | notiStyle.setSummaryText("+2 more Line Samples");
285 |
286 | try {
287 | remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
288 | } catch (IOException e) {
289 | e.printStackTrace();
290 | }
291 |
292 | // Creates an explicit intent for an ResultActivity to receive.
293 | Intent resultIntent = new Intent(this, ResultActivity.class);
294 |
295 | // This ensures that the back button follows the recommended convention for the back key.
296 | TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
297 |
298 | // Adds the back stack for the Intent (but not the Intent itself).
299 | stackBuilder.addParentStack(ResultActivity.class);
300 |
301 | // Adds the Intent that starts the Activity to the top of the stack.
302 | stackBuilder.addNextIntent(resultIntent);
303 | PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
304 |
305 | return new NotificationCompat.Builder(this)
306 | .setSmallIcon(R.drawable.ic_launcher)
307 | .setAutoCancel(true)
308 | .setLargeIcon(remote_picture)
309 | .setContentIntent(resultPendingIntent)
310 | .addAction(R.drawable.ic_launcher, "One", resultPendingIntent)
311 | .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent)
312 | .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent)
313 | .setContentTitle("Inbox Style Normal")
314 | .setContentText("This is an example of a Inbox Style.")
315 | .setStyle(notiStyle).build();
316 | }
317 |
318 | /**
319 | * Custom View Notification
320 | *
321 | * @return Notification
322 | * @see CreateNotification
323 | */
324 | private Notification setCustomViewNotification() {
325 |
326 | // Creates an explicit intent for an ResultActivity to receive.
327 | Intent resultIntent = new Intent(this, ResultActivity.class);
328 |
329 | // This ensures that the back button follows the recommended convention for the back key.
330 | TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
331 |
332 | // Adds the back stack for the Intent (but not the Intent itself)
333 | stackBuilder.addParentStack(ResultActivity.class);
334 |
335 | // Adds the Intent that starts the Activity to the top of the stack.
336 | stackBuilder.addNextIntent(resultIntent);
337 | PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
338 |
339 | // Create remote view and set bigContentView.
340 | RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.notification_custom_remote);
341 | expandedView.setTextViewText(R.id.text_view, "Neat logo!");
342 |
343 | Notification notification = new NotificationCompat.Builder(this)
344 | .setSmallIcon(R.drawable.ic_launcher)
345 | .setAutoCancel(true)
346 | .setContentIntent(resultPendingIntent)
347 | .setContentTitle("Custom View").build();
348 |
349 | notification.bigContentView = expandedView;
350 |
351 | return notification;
352 | }
353 |
354 | }
355 |
--------------------------------------------------------------------------------
/src/com/codeversed/example/Notifications/ResultActivity.java:
--------------------------------------------------------------------------------
1 | package com.codeversed.example.Notifications;
2 |
3 | import android.app.Activity;
4 |
5 | /**
6 | * User: stevealbright
7 | * Time: 9/10/13 @ 9:34 PM
8 | */
9 | public class ResultActivity extends Activity {
10 |
11 | }
12 |
--------------------------------------------------------------------------------