https://github.com/nicosnicolaou16/androidwidgetwithcompose
This project sets up the Widget in Android using Jetpack Compose Glance.
https://github.com/nicosnicolaou16/androidwidgetwithcompose
android android-app android-compose android-widget compose kotlin widget
Last synced: 7 months ago
JSON representation
This project sets up the Widget in Android using Jetpack Compose Glance.
- Host: GitHub
- URL: https://github.com/nicosnicolaou16/androidwidgetwithcompose
- Owner: NicosNicolaou16
- Created: 2024-02-10T23:18:19.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-28T22:39:17.000Z (about 1 year ago)
- Last Synced: 2025-03-23T06:41:22.472Z (11 months ago)
- Topics: android, android-app, android-compose, android-widget, compose, kotlin, widget
- Language: Kotlin
- Homepage: https://medium.com/@nicosnicolaou/android-widget-setup-with-jetpack-compose-glance-with-a-flutter-example-e07fb63c9466
- Size: 158 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Android Widget With Compose
This project sets up the Widget in Android using Jetpack Compose Glance.
# Setup
## Step 1 add the follow dependencies libraries
```Kotlin
val composeGlanceWidgetVersion by extra("1.1.1")
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
```Kotlin
class MyAppWidgetReceiver : GlanceAppWidgetReceiver() {
override val glanceAppWidget: GlanceAppWidget
get() = MyAppWidget()
}
```
## Step 3 Create the xml file into the xml directory (configuration to declare the size etc.)
```XML
```
## Step 4 Register the Receiver Class into the Manifest and set the xml configuration for the Glance Widget
```XML
```
## Step 5 Create the Widget that extend GlanceAppWidget() class
```Kotlin
//...
class MyAppWidget : GlanceAppWidget() {
override suspend fun provideGlance(context: Context, id: GlanceId) {
provideContent {
MyContent(context) //Compose UI
}
}
//....
}
```
> [!IMPORTANT]
> Check my article for the setup :point_right: [Android Widget Setup with Jetpack Compose Glance (with a Flutter example) - Medium](https://medium.com/@nicosnicolaou/android-widget-setup-with-jetpack-compose-glance-with-a-flutter-example-e07fb63c9466) :point_left:
> [!IMPORTANT]
> Similar project with (Dart Language) :point_right: [Android_Widget_With_Compose_With_Flutter](https://github.com/NicosNicolaou16/Android_Widget_With_Compose_With_Flutter) :point_left:
# Versioning
Target SDK version: 35
Minimum SDK version: 28
Kotlin version: 2.1.21
Gradle version: 8.10.1
# References
https://developer.android.com/jetpack/compose/glance/create-app-widget