Aktivität auf Display-KI-Brille über eine Benachrichtigung starten

XR‑Geräte, für die der Leitfaden gilt
Dieser Leitfaden hilft Ihnen dabei, Erlebnisse für die folgenden Arten von XR-Geräten zu entwickeln.
AI Glasses

Sie können eine andere PendingIntent angeben, die aufgerufen wird, wenn auf dem Brillendisplay auf eine Benachrichtigung getippt wird. Dieser PendingIntent unterscheidet sich vom Standard-Intent, der für das Smartphone mit setContentIntent festgelegt wurde. Wenn der Nutzer beispielsweise auf die Benachrichtigung auf der Display-KI-Brille tippt, wird eine bestimmte Brillenaktivität auf der Display-KI-Brille gestartet.

Verwenden Sie ProjectedExtender, um brillenspezifische Verhaltensweisen hinzuzufügen. Mit dieser API können Sie das Verhalten der Benachrichtigung auf der Brille anpassen, ohne dass sich dies auf die Darstellung auf dem Smartphone auswirkt.

Kotlin

// Intent to fire when tapped on the phone
val phoneIntent = Intent(this, MyPhoneActivity::class.java)
val phonePendingIntent = PendingIntent.getActivity(
    this, 0, phoneIntent, PendingIntent.FLAG_IMMUTABLE
)

// Intent to fire when tapped on the glasses display
val glassesIntent = Intent(this, MyGlassesActivity::class.java)
val glassesPendingIntent = PendingIntent.getActivity(
    this, 1, glassesIntent, PendingIntent.FLAG_IMMUTABLE
)

// Create the base notification
val builder = NotificationCompat.Builder(this, CHANNEL_ID).apply {
    setSmallIcon(R.drawable.ic_notification)
    setContentTitle("Navigation in Progress")
    setContentText("Tap to see details")
    // Default intent for phone
    setContentIntent(phonePendingIntent)

    // Create and apply the glasses extender
    val projectedExtender = ProjectedExtender().setContentIntent(glassesPendingIntent)

    extend(projectedExtender)
}

// Issue the notification
notificationManager.notify(NOTIFICATION_ID, builder.build())

Java

// Intent to fire when tapped on the phone
Intent phoneIntent = new Intent(this, MyPhoneActivity.class);
PendingIntent phonePendingIntent =
    PendingIntent.getActivity(this, 0, phoneIntent, PendingIntent.FLAG_IMMUTABLE);

// Intent to fire when tapped on the glasses display
Intent glassesIntent = new Intent(this, MyGlassesActivity.class);
PendingIntent glassesPendingIntent =
    PendingIntent.getActivity(this, 1, glassesIntent, PendingIntent.FLAG_IMMUTABLE);

// Create the base notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
    .setSmallIcon(R.drawable.ic_notification)
    .setContentTitle("New Update")
    .setContentText("Something important happened.")
    // Default intent for phone
    .setContentIntent(phonePendingIntent);

// Create and apply the Glasses extender
ProjectedExtender projectedExtender = new ProjectedExtender()
    // glasses-specific intent
    .setContentIntent(glassesPendingIntent);
builder.extend(projectedExtender);

// Issue the notification
notificationManager.notify(NOTIFICATION_ID, builder.build());