show Notification With Input For Primary Action - Android Android OS

Android examples for Android OS:Notification Show

Description

show Notification With Input For Primary Action

Demo Code

// Use of this source code is governed by the MIT license that can be found
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.NotificationCompat.WearableExtender;
import android.support.v4.app.RemoteInput;

public class Main{
    private static final String ACTION_TEST = "com.ezhuk.wear.ACTION";
    private static final String ACTION_EXTRA = "action";
    private static int NOTIFICATION_ID = 0;
    public static void showNotificationWithInputForPrimaryAction(
            Context context) {//  w w  w .j av  a 2 s  . com
        Intent intent = new Intent(ACTION_TEST);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                intent, 0);

        RemoteInput remoteInput = new RemoteInput.Builder(ACTION_EXTRA)
                .setLabel(context.getString(R.string.action_label))
                .setChoices(
                        context.getResources().getStringArray(
                                R.array.input_choices)).build();

        NotificationCompat.Action action = new NotificationCompat.Action.Builder(
                R.drawable.ic_launcher, "Action", pendingIntent)
                .addRemoteInput(remoteInput).build();

        NotificationManagerCompat.from(context).notify(
                getNewID(),
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setContentTitle(
                                context.getString(R.string.action_title))
                        .setContentText(
                                context.getString(R.string.action_text))
                        .setContentIntent(pendingIntent)
                        .extend(new WearableExtender().addAction(action))
                        .build());
    }
    private static synchronized int getNewID() {
        return NOTIFICATION_ID++;
    }
}

Related Tutorials