Android Wear远程语音输入到主要动作目的

问题描述:

根据Google提供的文档(http://developer.android.com/wear/notifications/remote-input.html),我正在玩Android Wear,但我陷入了可能缺少某些东西的部分。你们能帮忙吗?这是代码。Android Wear远程语音输入到主要动作目的

Intent viewIntent = new Intent(this, ActionActivity.class); 
     viewIntent.putExtra(getString(R.string.extraStringTag), extraString); 

PendingIntent viewPendingIntent = 
     PendingIntent.getActivity(this, 0, viewIntent, 0); 

Intent mapIntent = new Intent(Intent.ACTION_VIEW); 
Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode(location)); 
mapIntent.setData(geoUri); 
PendingIntent mapPendingIntent = 
     PendingIntent.getActivity(this, 0, mapIntent, 0); 

BigTextStyle bigStyle = new NotificationCompat.BigTextStyle(); 
bigStyle.bigText(eventDescription); 

String[] replyChoices = getResources().getStringArray(R.array.reply_choices); 
RemoteInput remoteInput = new RemoteInput.Builder(getString(R.string.extraStringTag)) 
     .setLabel(replyTitle) 
     .setChoices(replyChoices) 
     .build(); 

NotificationCompat.Builder notificationBuilder = 
     new NotificationCompat.Builder(this) 
     .setSmallIcon(R.drawable.questionblock) 
     .setLargeIcon(BitmapFactory.decodeResource(
       getResources(), R.drawable.mariopagebg)) 
     .setStyle(bigStyle) 
     .setContentTitle(eventTitle) 
     .setContentText(eventDescription) 
     .setContentIntent(viewPendingIntent) 
     .addAction(R.drawable.mariomap, 
       mapString, mapPendingIntent); 

Notification notification = new WearableNotifications.Builder(notificationBuilder) 
     .addRemoteInputForContentIntent(remoteInput) 
     .build(); 

// Get an instance of the NotificationManager service 
NotificationManagerCompat notificationManager = 
     NotificationManagerCompat.from(this); 

// Build the notification and issues it with notification manager. 
notificationManager.notify(notificationId, notification); 

正如在文档中声明的,我的主要操作按钮不会被转换为“答复”,因为它应该是。

+0

为了澄清事情,我的代码可能包含额外的代码块,我也尝试了文档中的确切代码,并且没有运气。 –

+0

代码中replyTitle的值是多少? –

+0

这是一个虚拟字符串,“回复标题” –

我解决了将活动添加到清单中的问题。一个诚实的错误。对于那些玩Android Wear的玩家,请记住,您没有添加到清单中的代码块中的待处理活动不会导致应用程序崩溃。你的堆栈跟踪中不会出现'丢失的类声明'。