I have 2 widgets in my app. Both are having the exact same features, but with different layouts. They work fine on every device, but it looks like there's an issue on Samsung devices. Every time I publish a new version of the app, the widget is removed from the user screen. It looks like this is a Samsung TouchWiz bug, but user are telling me other apps don't have this issue. Any idea of what's happening ?
BTW I thought for a moment that I found a way to fix it in this blog post: https://medium.com/the-wtf-files/the-mysterious-case-of-the-disappearing-widget-f4177a8e2c2b but I'm not calling manually
updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
Instead I'm calling
ComponentName cn = new ComponentName(context, clazz); AppWidgetManager.getInstance(context).updateAppWidget(cn, views);
in order to update my widgets
More of my code:
public static final int layout = R.layout.widget_large_layout;
public static final BitmapQualityEnum thumbnailQuality = BitmapQualityEnum.HIGH_RES;
public static final Class<?> clazz = LargeWidgetProvider.class;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
if (context != null && appWidgetIds != null && appWidgetIds.length > 0) {
// To prevent any ANR timeouts, we perform the update in a service
context.startService( new Intent(context, LargeWidgetProvider.UpdateService.class));
}
}
@Override
public void onReceive(Context context, Intent intent) {
if (context != null && intent != null) {
boolean doUpdate = true;
if ("android.appwidget.action.APPWIDGET_UPDATE".equals(intent.getAction())) {
final int[] widgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
doUpdate = (widgetIds != null && widgetIds.length > 0);
}
if (doUpdate) {
WidgetProviderHelper.receive(context, intent, clazz, layout, thumbnailQuality);
}
super.onReceive(context, intent);
}
}
public static class UpdateService extends Service {
private int serviceStartId = -1;
@Override
public boolean onUnbind(Intent intent) {
stopSelf(this.serviceStartId);
return true;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
this.serviceStartId = startId;
// Push update for this widget to the home screen
updateData(this);
return START_STICKY;
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// int oldOrientation = this.getResources().getConfiguration().orientation;
// if (newConfig.orientation != oldOrientation) {
// Update the widget) {
updateData(this);
// }
}
@Override
public IBinder onBind(Intent intent) {
// We don't need to bind to this service
return null;
}
}
I finally managed to solve my issue. The widget provider receivers need to be exported !!
<receiver
android:name=".widget.HorizontalWidgetProvider"
android:exported="true" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="com.customEvent" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_horizontal_provider" />
</receiver>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With