Home | History | Annotate | Download | only in app
      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;
     22 import android.app.Notification;
     23 import android.app.NotificationManager;
     24 import android.app.PendingIntent;
     25 import android.app.TaskStackBuilder;
     26 import android.content.Intent;
     27 import android.os.Bundle;
     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);
     35     }
     36 
     37     public void onPostDirect(View v) {
     38         Notification.Builder builder = new Notification.Builder(this)
     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)
     44                 .setContentIntent(TaskStackBuilder.create(this)
     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) {
     54         Notification.Builder builder = new Notification.Builder(this)
     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 }
     68