Android

Jetpack Glance

Jetpack Glance: A Modern Way to Build App Widgets in Android

Widgets are one of the oldest and most-loved features of Android. They let users access app content directly from the home screen, offering convenience, quick interactions, and persistent information. But let’s be honest — building widgets used to be a pain. If you’ve ever dealt with RemoteViews, you probably remember how clunky and restrictive it felt. From...

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
Jetpack Glance Media Playback

A Deep Dive into Using Jetpack Glance for Media Playback in Android Automotive OS

As vehicles evolve into digital experiences, the need for glanceable, fast, and distraction-free interfaces becomes paramount. In Android Automotive OS (AAOS), this demand has led to the emergence of the Jetpack Glance framework — a powerful tool for creating UI surfaces that are lightweight, fast to load, and safe for drivers to interact with.

In this blog post, we’ll explore how Jetpack Glance can be used to build a media playback card for Android Automotive OS. From setting up dependencies to implementing a full-featured glanceable media widget with play/pause/skip functionality — we’ll walk through the full picture with code, context, and best practices.

What is Jetpack Glance?

Jetpack Glance is a declarative UI library designed for building remote user interfaces, including:

  • App widgets (for Android homescreens)
  • Glanceable UIs for wearables (e.g., Tiles)
  • Future-facing vehicle dashboards and clusters in Android Automotive

Think of Glance as the Compose-inspired sibling of RemoteViews, but tailored for rendering quickly, efficiently, and safely on surfaces with strict interaction rules — like a car’s infotainment screen.

Why Use Glance in Android Automotive?

Using Glance in AAOS allows developers to:

  • Create lightweight UIs for media, navigation, or vehicle info
  • Ensure low distraction by adhering to system-level constraints
  • Maintain fast rendering even on constrained hardware
  • Leverage Jetpack Compose-like syntax without full Compose overhead

Key Use Cases in AAOS

Use CaseDescription
Media CardsDisplay now-playing info and basic playback controls
Navigation PreviewsShow turn-by-turn summaries or route cards
Vehicle StatusFuel, tire pressure, battery charge level
Contextual AlertsDoor open, low fuel, safety notifications

Setting Up Jetpack Glance in Your Project

Add Required Dependencies

Update your build.gradle with the latest Glance libraries:

Kotlin
dependencies {
    implementation "androidx.glance:glance:1.0.0"
    implementation "androidx.glance:glance-appwidget:1.0.0"
    implementation "androidx.glance:glance-wear-tiles:1.0.0" // optional
    implementation "androidx.core:core-ktx:1.12.0"
}

Tip: Glance is backward-compatible with Android 12 and above, making it suitable for most AAOS setups.

Creating a Glanceable Media Widget for AAOS

Let’s walk through a full example where we build a media playback widget that can be shown in a center display or cluster (with OEM support).

Define the Glance Widget

Kotlin
class MediaGlanceWidget : GlanceAppWidget() {
    @Composable
    override fun Content() {
        val title = "Song Title"
        val artist = "Artist Name"

        Column(
            modifier = GlanceModifier
                .fillMaxSize()
                .padding(16.dp)
                .background(Color.DarkGray),
            verticalAlignment = Alignment.CenterVertically,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Text("Now Playing", style = TextStyle(fontWeight = FontWeight.Bold, color = Color.White))
            Spacer(Modifier.height(8.dp))
            Text(title, style = TextStyle(color = Color.White))
            Text(artist, style = TextStyle(color = Color.LightGray))

            Spacer(Modifier.height(16.dp))
            Row(horizontalAlignment = Alignment.CenterHorizontally) {
                Image(
                    provider = ImageProvider(R.drawable.ic_previous),
                    contentDescription = "Previous",
                    modifier = GlanceModifier.size(32.dp).clickable {
                        actionStartService<MediaControlService>("ACTION_PREVIOUS")
                    }
                )
                Spacer(Modifier.width(16.dp))
                Image(
                    provider = ImageProvider(R.drawable.ic_play),
                    contentDescription = "Play",
                    modifier = GlanceModifier.size(32.dp).clickable {
                        actionStartService<MediaControlService>("ACTION_PLAY_PAUSE")
                    }
                )
                Spacer(Modifier.width(16.dp))
                Image(
                    provider = ImageProvider(R.drawable.ic_next),
                    contentDescription = "Next",
                    modifier = GlanceModifier.size(32.dp).clickable {
                        actionStartService<MediaControlService>("ACTION_NEXT")
                    }
                )
            }
        }
    }
}

Handling Playback Actions: MediaControlService

Since Glance doesn’t support direct onClick behavior like Compose, we use a Service to act on UI interactions.

Kotlin
class MediaControlService : Service() {
    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        when (intent?.action) {
            "ACTION_PLAY_PAUSE" -> togglePlayPause()
            "ACTION_NEXT" -> skipToNext()
            "ACTION_PREVIOUS" -> skipToPrevious()
        }
        return START_NOT_STICKY
    }

    private fun togglePlayPause() {
        // Hook into MediaSession or ExoPlayer
    }

    private fun skipToNext() {
        // Forward playback command
    }

    private fun skipToPrevious() {
        // Rewind playback
    }

    override fun onBind(intent: Intent?): IBinder? = null
}

Integrating with AndroidManifest.xml

To register the widget and service:

Kotlin
<receiver
    android:name=".MediaGlanceWidgetReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>
    <meta-data
        android:name="android.appwidget.provider"
        android:resource="@xml/media_widget_info" />
</receiver>

<service
    android:name=".MediaControlService"
    android:exported="false" />

Widget Configuration XML

In res/xml/media_widget_info.xml:

Kotlin
<appwidget-provider
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="180dp"
    android:minHeight="100dp"
    android:updatePeriodMillis="60000"
    android:widgetCategory="home_screen" />

Best Practices for Automotive Glance UI

  • Keep UI distraction-optimized
  • Use readable font sizes and sufficient contrast
  • Avoid overloading the interface — 2–3 actions max
  • Make controls large and touch-friendly
  • Always test on real AAOS hardware or emulator

Conclusion

Jetpack Glance is quickly becoming a go-to tool for developers looking to build safe, fast, and flexible UI surfaces across Android form factors. In the automotive space, it shines by helping deliver minimalist, glanceable media controls that respect both performance and safety constraints.

As AAOS continues to evolve, expect more OEM support for Glance in clusters, dashboards, and center displays — especially with the push toward custom car launchers and immersive media experiences

What Is KDoctor? The Essential Tool Every Kotlin Multiplatform Developer Must Know in 2025

If you’re diving into Kotlin Multiplatform Mobile (KMM) development in 2025, chances are you’ve already come across tools like Android Studio, Xcode, and Gradle. But there’s one small, powerful tool that can make or break your setup experience: KDoctor. In this blog, we’ll explore what KDoctor is, why it’s a must-have for Kotlin Multiplatform developers,...

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
flutterVsReactNativeVsKMM

KMM vs Flutter vs React Native: Which Cross-Platform Tool Wins in 2025?

If you’re building mobile apps in 2025, there’s a good chance you’re thinking cross-platform. Why write separate code for Android and iOS when you can hit both with one codebase? That’s the promise — and the pain — of cross-platform development. Three tools are dominating the conversation: Kotlin Multiplatform Mobile (KMM), Flutter, and React Native. They’re all capable, widely...

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
android in automotive industry

The Journey of Android in the Automotive Industry

Android has come a long way since powering our phones. Today, it’s in dashboards, infotainment systems, and even under the hood of cars. But how exactly did Android evolve from a smartphone OS to a critical player in the automotive world? In this blog post, we’ll explore the fascinating journey of Android in the automotive...

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
Glanceable UI

Implementing Glanceable UI with Jetpack Glance in Android Automotive OS

Glanceable UI is a key pillar of in-car user experiences, especially in vehicles powered by Android Automotive OS (AAOS). With safety at the core, designing for “at-a-glance” interaction ensures drivers get the information they need with minimal distraction. In this blog post, we’ll explore: What Jetpack Glance is How it helps build Glanceable UIs for...

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
Google Automotive Services (GAS)

What Is Google Automotive Services (GAS) and How It’s Transforming the In-Car Experience

Imagine stepping into your car, and it feels just like using your smartphone — personalized apps, Google Assistant ready to help, Maps guiding you smoothly, and even YouTube available for in-vehicle entertainment. This isn’t a far-off dream anymore. Thanks to Google Automotive Services (GAS), the in-car digital experience is becoming smarter, more connected, and refreshingly user-friendly. In...

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
android auto to android automotive os

From Android Auto to Android Automotive OS: Why This Shift Is Revolutionizing In-Car Tech

For years, Android Auto has been the go-to solution for connecting smartphones to car infotainment systems. But there’s a new player in town — and it’s not just an upgrade; it’s a complete transformation. Say hello to Android Automotive OS. This shift from Android Auto to Android Automotive OS isn’t just a tech tweak. It’s a fundamental...

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
how Android Automotive OS minimizes distractions and ensures road safety

How Android Automotive OS Achieves Fewer Distractions with Safety in Mind

In today’s connected car world, balancing functionality with driver safety is non-negotiable. That’s exactly why Android Automotive OS (AAOS) was designed with a “safety-first” philosophy. Unlike smartphones, AAOS runs directly on a vehicle’s infotainment system, where distractions can literally cost lives. In this post, let’s explore how Android Automotive minimizes distractions and ensures road safety...

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
Jetpack Compose UI Components

The Ultimate Guide to Jetpack Compose UI Components

Jetpack Compose has revolutionized Android UI development by providing a declarative approach to building modern and dynamic user interfaces. If you’re new to Jetpack Compose or looking for a comprehensive guide on UI components, this blog will walk you through the essential elements used to create stunning Android apps. From basic text displays to complex...

Membership Required

You must be a member to access this content.

View Membership Levels

Already a member? Log in here
error: Content is protected !!