1 /* 2 * Copyright (C) 2016 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 package android.content.pm.cts.shortcutmanager.throttling; 17 18 import static android.content.pm.cts.shortcutmanager.common.Constants.INLINE_REPLY_REMOTE_INPUT_CAPTION; 19 import static android.content.pm.cts.shortcutmanager.common.Constants.INLINE_REPLY_TITLE; 20 21 import android.app.Notification; 22 import android.app.Notification.Action; 23 import android.app.Notification.Builder; 24 import android.app.NotificationManager; 25 import android.app.PendingIntent; 26 import android.app.RemoteInput; 27 import android.content.BroadcastReceiver; 28 import android.content.ComponentName; 29 import android.content.Context; 30 import android.content.Intent; 31 32 public class InlineReply extends BroadcastReceiver { 33 private static final String EXTRA_REPLY_ACTION = "reply"; 34 35 @Override 36 public void onReceive(Context context, Intent intent) { 37 context.getSystemService(NotificationManager.class).cancelAll(); 38 } 39 40 public static void showNotificationWithInlineReply(Context context) { 41 final PendingIntent receiverIntent = 42 PendingIntent.getBroadcast(context, 0, 43 new Intent().setComponent(new ComponentName(context, InlineReply.class)), 44 PendingIntent.FLAG_UPDATE_CURRENT); 45 final RemoteInput ri = new RemoteInput.Builder("result").setLabel("Remote input").build(); 46 47 final Notification.Builder nb = new Builder(context) 48 .setContentText("Test") 49 .setContentTitle(INLINE_REPLY_TITLE) 50 .setSmallIcon(android.R.drawable.ic_popup_sync) 51 .addAction(new Action.Builder(0, INLINE_REPLY_REMOTE_INPUT_CAPTION, receiverIntent) 52 .addRemoteInput(ri) 53 .build()); 54 context.getSystemService(NotificationManager.class).notify(0, nb.build()); 55 } 56 } 57