Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Widget disappearing every time the app is updated on Samsung devices

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;
        }
    }
like image 418
user1026605 Avatar asked Jun 06 '14 21:06

user1026605


1 Answers

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>
like image 149
user1026605 Avatar answered Oct 20 '22 00:10

user1026605