Scroll Essential Android 2.3 Manual de usuario Pagina 23

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 47
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 22
Android Wear Docs, Release 1.1
NotificationCompat.WearableExtender wearableExtender =
new NotificationCompat.WearableExtender()
.addAction(replyAction);
6. Create a notification and extended it with the wearable extender just created. The following example creates a
notification that includes a reply action (demand).
Notification notification =
new NotificationCompat.Builder(this)
.setContentTitle("Hello Wearable!")
.setContentText("First Wearable demand.")
.setSmallIcon(R.drawable.ic_launcher)
.extend(wearableExtender)
.build();
7. Get an instance of the Notification Manager service.
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
8. Dispatch the extended notification.
int notificationId, notification;
notificationManager.notify(notificationId, notification);
4.1.3 Create a Demand Receiver
When a user makes a demand, the wearable broadcasts an intent that contains the details. The handheld receives the
broadcast and takes an appropriate action. The following example defines a BroadcastReceiver for a voice demand
that simply logs the results.
public class DemandIntentReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Handheld.ACTION_DEMAND)) {String message =
intent.getStringExtra(Handheld.EXTRA_MESSAGE);
Log.v("MyTag","Extra message from intent = " + message);
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
CharSequence reply = remoteInput.getCharSequence(Handheld.EXTRA_VOICE_REPLY);
Log.v("MyTag", "User reply from wearable: " + reply);
}
}
}
You also need to modify the manifest file to accept the broadcast. Add a receiver section within the application section.
<receiver android:name=".DemandIntentReceiver" android:exported="false">
<intent-filter>
<action android:name="com.androidweardocs.first_wearable.ACTION_DEMAND"/>
</intent-filter>
</receiver>
The sample code first displays the notification text, which is simply a title and body. Swiping to the left displays the
reply icon with the reply label.
4.1. First Android Wear Demand 19
Vista de pagina 22
1 2 ... 18 19 20 21 22 23 24 25 26 27 28 ... 46 47

Comentarios a estos manuales

Sin comentarios