blob: cfb3b427a413171b1f796c654dbae532c48bf487 [file] [log] [blame]
Adam Powell247df4f2012-01-17 09:36:47 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.example.android.appnavigation.app;
18
19import com.example.android.appnavigation.R;
20
21import android.app.Activity;
Adam Powelle3316662012-04-05 17:07:02 -070022import android.app.Notification;
Adam Powell247df4f2012-01-17 09:36:47 -080023import android.app.NotificationManager;
24import android.app.PendingIntent;
Adam Powelle3316662012-04-05 17:07:02 -070025import android.app.TaskStackBuilder;
Adam Powell247df4f2012-01-17 09:36:47 -080026import android.content.Intent;
27import android.os.Bundle;
Adam Powell247df4f2012-01-17 09:36:47 -080028import android.view.View;
29
30public class NotificationsActivity extends Activity {
31 @Override
32 protected void onCreate(Bundle savedInstanceState) {
33 super.onCreate(savedInstanceState);
34 setContentView(R.layout.notifications);
Adam Powell247df4f2012-01-17 09:36:47 -080035 }
36
37 public void onPostDirect(View v) {
Adam Powelle3316662012-04-05 17:07:02 -070038 Notification.Builder builder = new Notification.Builder(this)
Adam Powell247df4f2012-01-17 09:36:47 -080039 .setTicker("Direct Notification")
40 .setSmallIcon(android.R.drawable.stat_notify_chat)
41 .setContentTitle("Direct Notification")
42 .setContentText("This will open the content viewer")
43 .setAutoCancel(true)
Adam Powellffb145c2012-05-01 18:25:01 -070044 .setContentIntent(TaskStackBuilder.create(this)
Adam Powell247df4f2012-01-17 09:36:47 -080045 .addParentStack(ContentViewActivity.class)
46 .addNextIntent(new Intent(this, ContentViewActivity.class)
47 .putExtra(ContentViewActivity.EXTRA_TEXT, "From Notification"))
48 .getPendingIntent(0, 0));
49 NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
50 nm.notify("direct_tag", R.id.direct_notification, builder.getNotification());
51 }
52
53 public void onPostInterstitial(View v) {
Adam Powelle3316662012-04-05 17:07:02 -070054 Notification.Builder builder = new Notification.Builder(this)
Adam Powell247df4f2012-01-17 09:36:47 -080055 .setTicker("Interstitial Notification")
56 .setSmallIcon(android.R.drawable.stat_notify_chat)
57 .setContentTitle("Interstitial Notification")
58 .setContentText("This will show a detail page")
59 .setAutoCancel(true)
60 .setContentIntent(PendingIntent.getActivity(this, 0,
61 new Intent(this, InterstitialMessageActivity.class)
62 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
63 Intent.FLAG_ACTIVITY_CLEAR_TASK), 0));
64 NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
65 nm.notify("interstitial_tag", R.id.interstitial_notification, builder.getNotification());
66 }
67}