如何捕捉其中,onAppWidgetOptionsChanged没有得到要求的设备部件尺寸的变化? [英] How to catch widget size changes on devices where onAppWidgetOptionsChanged not getting called?

查看:253
本文介绍了如何捕捉其中,onAppWidgetOptionsChanged没有得到要求的设备部件尺寸的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设备像三星Galaxy S3在与Android版本4.1.2有哪些prevents onAppWidgetOptionsChanged被称为一个bug。

Devices like Samsung Galaxy S3 working with Android version 4.1.2 has a bug which prevents onAppWidgetOptionsChanged to be called.

那么,我们如何才能与改变大小的信息?

So, how can we get information related to changed sizes?

推荐答案

我增加了法兰克的回答着如何我处理接收到这个广播:

I am adding to Frankish's answer with how I handle receiving this broadcast:

@Override
public void onReceive(Context context, Intent intent) {
    // Handle TouchWiz
    if(intent.getAction().contentEquals("com.sec.android.widgetapp.APPWIDGET_RESIZE")) {
        handleTouchWiz(context, intent);
    }
    super.onReceive(context, intent);
}

private void handleTouchWiz(Context context, Intent intent) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

    int appWidgetId = intent.getIntExtra("widgetId", 0);
    int widgetSpanX = intent.getIntExtra("widgetspanx", 0);
    int widgetSpanY = intent.getIntExtra("widgetspany", 0);

    if(appWidgetId > 0 && widgetSpanX > 0 && widgetSpanY > 0) {
        Bundle newOptions = new Bundle();
        // We have to convert these numbers for future use
        newOptions.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, widgetSpanY * 74);
        newOptions.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, widgetSpanX * 74);

        onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
    }
}

您可能需要改变你如何,如果你使用的是MAX_HEIGHT或MAX_WIDTH对此我无法处理的包。

You may need to change how you handle that bundle if you are using MAX_HEIGHT or MAX_WIDTH which I am not.

这篇关于如何捕捉其中,onAppWidgetOptionsChanged没有得到要求的设备部件尺寸的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆