10

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;
        }
    }
user1026605
  • 1,633
  • 4
  • 22
  • 58
  • I had issues with disappearing widgets (and icons) on Samsung devices too and it turned out that enabling/disabling components in my app programmatically (components unrelated to the widgets itself) messed up TouchWiz. If you post more of your widget code (like the onReceive/onUpdate I could check it for potential issues. – Emanuel Moecklin Jun 23 '14 at 14:04
  • I get the argument "your app has this issue but other apps don't" a lot. The counter argument could be "99.9% of my hundred of thousands of users don't have this issue, so what's wrong with your device?" ;-). If one app out of let's say 200 has an issue (0.5%) compared to 5 devices out of 100'000 installations having that issue (0.005%) then obviously the likelihood that the device has a problem is higher than the app having a problem. Of course the truth is usually somewhere in between and it's usually a combination of factors). – Emanuel Moecklin Jun 23 '14 at 14:12
  • @Emanuel Moecklin it doesn't matter if only a few users are having the issue. Yes maybe 20 users reported the issue out of 500K+ but they all have a samsung device in common. Also most users aren't using the app widget and most user don't complain about issues thay might have. So yes I want to fix this issue ;) – user1026605 Jun 24 '14 at 07:53
  • also see my answer here: https://stackoverflow.com/a/49136980/550393 – 2cupsOfTech Mar 10 '18 at 22:14

1 Answers1

3

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>
user1026605
  • 1,633
  • 4
  • 22
  • 58
  • 3
    According to this http://developer.android.com/guide/topics/manifest/receiver-element.html#exported the exported flag should automatically set to true if the receiver has an intent-filter so I guess that's another TouchWiz bug. – Emanuel Moecklin Jul 08 '14 at 20:19