Adam Powell | 247df4f | 2012-01-17 09:36:47 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.example.android.appnavigation.app; |
| 18 | |
| 19 | import com.example.android.appnavigation.R; |
| 20 | |
| 21 | import android.app.Activity; |
Adam Powell | e331666 | 2012-04-05 17:07:02 -0700 | [diff] [blame] | 22 | import android.app.Notification; |
Adam Powell | 247df4f | 2012-01-17 09:36:47 -0800 | [diff] [blame] | 23 | import android.app.NotificationManager; |
| 24 | import android.app.PendingIntent; |
Adam Powell | e331666 | 2012-04-05 17:07:02 -0700 | [diff] [blame] | 25 | import android.app.TaskStackBuilder; |
Adam Powell | 247df4f | 2012-01-17 09:36:47 -0800 | [diff] [blame] | 26 | import android.content.Intent; |
| 27 | import android.os.Bundle; |
Adam Powell | 247df4f | 2012-01-17 09:36:47 -0800 | [diff] [blame] | 28 | import android.view.View; |
| 29 | |
| 30 | public class NotificationsActivity extends Activity { |
| 31 | @Override |
| 32 | protected void onCreate(Bundle savedInstanceState) { |
| 33 | super.onCreate(savedInstanceState); |
| 34 | setContentView(R.layout.notifications); |
Adam Powell | 247df4f | 2012-01-17 09:36:47 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | public void onPostDirect(View v) { |
Adam Powell | e331666 | 2012-04-05 17:07:02 -0700 | [diff] [blame] | 38 | Notification.Builder builder = new Notification.Builder(this) |
Adam Powell | 247df4f | 2012-01-17 09:36:47 -0800 | [diff] [blame] | 39 | .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 Powell | ffb145c | 2012-05-01 18:25:01 -0700 | [diff] [blame] | 44 | .setContentIntent(TaskStackBuilder.create(this) |
Adam Powell | 247df4f | 2012-01-17 09:36:47 -0800 | [diff] [blame] | 45 | .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 Powell | e331666 | 2012-04-05 17:07:02 -0700 | [diff] [blame] | 54 | Notification.Builder builder = new Notification.Builder(this) |
Adam Powell | 247df4f | 2012-01-17 09:36:47 -0800 | [diff] [blame] | 55 | .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 | } |