Skip to content

Latest commit

 

History

History
68 lines (63 loc) · 1.93 KB

README.md

File metadata and controls

68 lines (63 loc) · 1.93 KB

WidgetWithCompose

Simple android widget by using glance library, you can get to the android documentation here

Implementation

build.gradle (module)

dependencies {
    implementation "androidx.glance:glance:1.0.0-alpha05"
    implementation "androidx.glance:glance-appwidget:1.0.0-alpha05"
}


CounterWidget.kt

object CounterWidget :  GlanceAppWidget() {
    @Composable
    override fun Content() {
        ...
    }
}

class SimpleCounterWidgetReceiver : GlanceAppWidgetReceiver() {
    override val glanceAppWidget: GlanceAppWidget
        get() = CounterWidget
}

class IncrementActionCallback : ActionCallback {
    override suspend fun onAction(
        context: Context,
        glanceId: GlanceId,
        parameters: ActionParameters
    ) {
        ...
    }
}


counter_widget_info.xml

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="@string/app_name"
    android:minWidth="200dp"
    android:minHeight="100dp"
    android:resizeMode="horizontal|vertical"
    android:widgetCategory="home_screen" />


AndroidManifest.xml

<manifest>
    <application>
        <activity>...</activity>
        ...
  
        <receiver
            android:name=".SimpleCounterWidgetReceiver"
            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/counter_widget_info" />
        </receiver>
    </application>
</manifest>

preview :

drawing