Closed Brunowilliang closed 5 months ago
Hi,
Just to confirm, have you opened the app before trying to add a widget? If so, try with v 0.6.20.
If that works, then I'll investigate further. If not, please check you haven't missed something and importantly reduce your widget to the bare minimum to check there isn't a runtime error within your kotlin
Hey @gitn00b1337, I tested it on versions 0.6.20 and 0.7.0 the same problem occurs...
I just took the widgets from the example project, I didn't change much.
and followed the steps to set it up:
[
"@bittingz/expo-widgets",
{
android: {
src: "./widgets/android",
resourceName: "@xml/my_widget_info",
}
}
],
and I added the name of my package along with the '.R' because it was giving me an error.
package ie.idonate.com
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
import android.widget.RemoteViews
import android.content.SharedPreferences
import ie.idonate.com.R
/**
* Implementation of App Widget functionality.
*/
class SampleWidget : AppWidgetProvider() {
override fun onUpdate(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetIds: IntArray
) {
// There may be multiple widgets active, so update all of them
for (appWidgetId in appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId)
}
}
override fun onEnabled(context: Context) {
// Enter relevant functionality for when the first widget is created
}
override fun onDisabled(context: Context) {
// Enter relevant functionality for when the last widget is disabled
}
}
internal fun updateAppWidget(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetId: Int
) {
val data = context.getSharedPreferences(context.packageName + ".widgetdata", Context.MODE_PRIVATE).getString("widgetdata", "{}")
val views = RemoteViews(context.packageName, R.layout.sample_widget)
views.setTextViewText(R.id.appwidget_text, data)
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views)
}
Ok, does ie.idonate.com match your package name for app.json (android.package)?
Also, I think the example above might be missing this:
[
"@bittingz/expo-widgets",
{
"android": {
"src": "./widgets/android",
"widgets": [
{
"name": "SampleWidget",
"resourceName": "@xml/sample_widget_info"
}
]
}
}
],
I've updated the readme; I added multiple widget support a few months ago and clearly forgot the docs
I've updated the example project with more details. You can pull down and follow the steps in App.tsx to get a working example
I followed the step-by-step guide to add the widget to my app. I can build it with:
and the app works fine, but the widget doesn't appear. The widget only becomes visible when I add the following configuration to the AndroidManifest.xml: