Home > Back-end >  How to create home screen or lock screen widget using jetpack compose
How to create home screen or lock screen widget using jetpack compose

Time:12-15

I want to implement home screen or lock screen widgets using jetpack compose.

I do some R&D but I didn't find any document related to this topic.

So help me.

Thank you in advanced

CodePudding user response:

Jetpack Compose Glance to create app widgets is in alpha but you can access it by adding this dependency to your project:

implementation "androidx.glance:glance-appwidget:1.0.0-alpha05"

You then need to extend your class to GlanceAppWidgets. Here is a code snippet from the doc:

class GreetingsWidget(private val name: String): GlanceAppWidget() {
    @Composable
    override fun Content() {
        Text(text = "Hello $name")
    }
}

class GreetingsWidgetReceiver : GlanceAppWidgetReceiver() {

    override val glanceAppWidget = GreetingsWidget("Glance")
}

Please have a look here for the documentation.

  • Related