Voice input with Android Wear Preview

前提是你 提交于 2019-12-06 14:56:39

I solved my issued by using the following code:

protected void voiceNotification() {

        // Creo l'intent per l'azione di risposta
        Intent replyIntent = new Intent(this, ReplyActivity.class);

        // Aggiungo l'intent alla coda
        PendingIntent replyPendingIntent = PendingIntent.getActivity(this, 0, replyIntent, 0);

        // Creo la notifica
        NotificationCompat.Builder replyNotificationBuilder = new NotificationCompat.Builder(this);
        replyNotificationBuilder.setSmallIcon(android.R.drawable.ic_btn_speak_now);
        replyNotificationBuilder.setContentTitle("Messaggio");
        replyNotificationBuilder.setContentText("Testo del messaggio");
        replyNotificationBuilder.setContentIntent(replyPendingIntent);
        replyNotificationBuilder.setNumber(++numMessages);
        replyNotificationBuilder.setAutoCancel(true);
        replyNotificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        replyNotificationBuilder.setVibrate(new long[]{1000, 1000});
        replyNotificationBuilder.setTicker("Hai una nuova notifica!");

        // Invio la notifica al notification manager
        mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(notificationID, replyNotificationBuilder.build());

        // Creo il remote input
        RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(getResources().getString(R.string.reply_label)).build();

        // Creo la notifica compact
        Notification replyNotification = new WearableNotifications.Builder(replyNotificationBuilder).addRemoteInputForContentIntent(remoteInput).build();

        // Passo la notifica appena creata al notification manager compat
        NotificationManagerCompat.from(this).notify(0, replyNotification);
    }

I hope that will be useful for other person.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!