This project is the setup for the Widget in Android with Jetpack Compose Glance.
https://github.com/NicosNicolaou16/Android_Widget_With_Compose_With_Flutter
Target SDK version: 34
Minimum SDK version: 27
Kotlin version: 1.9.23
Gradle version: 8.4.0
val composeGlanceWidgetVersion by extra("1.0.0")
dependencies {
//...
//Glance Widget
implementation("androidx.glance:glance-appwidget:$composeGlanceWidgetVersion")
//Using Material 2
implementation("androidx.glance:glance-material:$composeGlanceWidgetVersion")
//Using Material 3
implementation("androidx.glance:glance-material3:$composeGlanceWidgetVersion")
}
Steps 2 Create the Glance Receiver class that extend GlanceAppWidgetReceiver() and return the Widget Class
class MyAppWidgetReceiver : GlanceAppWidgetReceiver() {
override val glanceAppWidget: GlanceAppWidget
get() = MyAppWidget()
}
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/glance_default_loading_layout" android:minWidth="250dp"
android:minHeight="50dp" android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen">
</appwidget-provider>
Step 4 Register the Receiver Class into the Manifest and set the xml configuration for the Glance Widget
<receiver android:name=".glance_widget.receiver.MyAppWidgetReceiver" 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/my_app_widget_info" />
</receiver>
//...
class MyAppWidget : GlanceAppWidget() {
override suspend fun provideGlance(context: Context, id: GlanceId) {
provideContent {
MyContent(context) //Compose UI
}
}
//....
}
https://developer.android.com/jetpack/compose/glance/create-app-widget