Java tutorial
/*** Copyright (c) 2014 CommonsWare, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Covered in detail in the book _The Busy Coder's Guide to Android Development_ https://commonsware.com/Android */ package com.commonsware.android.wearvoice; import android.app.Activity; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationManagerCompat; import android.support.v4.app.RemoteInput; public class MainActivity extends Activity { private static final int NOTIFY_ID = 1337; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent i = new Intent(this, VoiceReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInput = new RemoteInput.Builder(VoiceReceiver.EXTRA_SPEECH) .setLabel(getString(R.string.talk)).setChoices(getResources().getStringArray(R.array.replies)) .build(); NotificationCompat.Action wearAction = new NotificationCompat.Action.Builder( android.R.drawable.ic_btn_speak_now, getString(R.string.talk), pi).addRemoteInput(remoteInput) .build(); NotificationCompat.WearableExtender wearExtender = new NotificationCompat.WearableExtender() .addAction(wearAction); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.stat_sys_download_done).setContentTitle(getString(R.string.title)) .setContentText(getString(R.string.talk)).extend(wearExtender); NotificationManagerCompat.from(this).notify(NOTIFY_ID, builder.build()); finish(); } }