notification With Reply - Android Android OS

Android examples for Android OS:Notification

Description

notification With Reply

Demo Code


import android.app.Activity;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import java.io.IOException;

public class Main{
    private static final int NOTIFICATION_ID = 1;
    public static void notificationWithReply(Context ctx) {
        RemoteInput remoteInput = new RemoteInput.Builder(
                DetalheActivity.EXTRA_VOICE_REPLY).setLabel(
                "Diga a resposta").build();

        Intent replyIntent = new Intent(ctx, DetalheActivity.class);
        PendingIntent replyPendingIntent = PendingIntent.getActivity(ctx,
                0, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Action action = new NotificationCompat.Action.Builder(
                R.drawable.ic_reply, "Responder", replyPendingIntent)
                .addRemoteInput(remoteInput).build();

        NotificationCompat.WearableExtender nwe = new NotificationCompat.WearableExtender();
        Notification notification = newNotification(ctx, "Com resposta",
                "Passe a p?gina para responder").extend(
                nwe.addAction(action)).build();
        dispatchNotification(ctx, notification, NOTIFICATION_ID);
    }/*w ww.j av a 2s .  c  om*/
    private static NotificationCompat.Builder newNotification(Context ctx,
            String title, String text) {

        return new NotificationCompat.Builder(ctx)
                .setSmallIcon(R.drawable.ic_like).setContentTitle(title)
                .setContentText(text).setAutoCancel(true)
                .setDefaults(NotificationCompat.DEFAULT_ALL);
    }
    private static void dispatchNotification(Context ctx,
            Notification notification, int id) {

        NotificationManagerCompat notificationManager = NotificationManagerCompat
                .from(ctx);
        notificationManager.notify(id, notification);
    }
}

Related Tutorials