Android - Samsung:使用配置活动创建Widget失败 [英] Android - Samsung: Creating Widget with configuration activity fails

查看:144
本文介绍了Android - Samsung:使用配置活动创建Widget失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个可以将小部件添加到主屏幕的应用程序。小部件正在使用我的Nexus 6P和摩托罗拉Moto G3。

I built an application with the possibility to add widgets to the home screen. The widget is working with my Nexus 6P and a Motorola Moto G3.

使用三星手机(经S3 mini(4.1.2)测试,S5,S6(6.0.1) ))小部件根本没有添加或TouchWiz崩溃。

With Samsung Phones (Tested with S3 mini (4.1.2), S5, S6 (6.0.1)) the widget is not added at all or TouchWiz crashes.

使用另一个启动器(Nova),小部件也不会在S3 mini上创建。

With another launcher (Nova) the widget is also not created on the S3 mini.

在logcat中我根本没有看到任何错误消息。

In logcat I don't see any error message at all.

我试图尽可能缩小问题范围。
如果我从counter_widget_info.xml中删除 android:configure =de.cliff.strichliste.widgets.WidgetConfigurationActivity,则会创建小部件。如果我想使用配置活动,TouchWiz会在Samsung S3 mini上崩溃。

I tried to narrow the problem down as far as possible. The widget gets created if I remove the android:configure="de.cliff.strichliste.widgets.WidgetConfigurationActivity" from the counter_widget_info.xml. If I want to use a configuration activity TouchWiz crashes on the Samsung S3 mini.

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="40dp"
    android:minHeight="40dp"
    android:configure="de.cliff.strichliste.widgets.WidgetConfigurationActivity"
    android:updatePeriodMillis="1800000"
    android:initialLayout="@layout/widget_counter"
    android:resizeMode="horizontal|vertical"
    android:widgetCategory="home_screen"
    android:previewImage="@drawable/widget_preview">
</appwidget-provider>

在AndroidManifest.xml中,我使用以下行注册小部件:

In the AndroidManifest.xml I register the widget with the following lines:

<receiver
            android:name=".widgets.CounterWidgetProvider">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/counter_widget_info" />
</receiver>

在Java方面,我在WidgetConfigurationActivity中有以下内容:

On the Java side, I've got the following in the WidgetConfigurationActivity:

public class WidgetConfigurationActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WidgetConfigurationBinding binding = DataBindingUtil.setContentView(this, R.layout.widget_configuration);
        setResult(RESULT_OK);
    }
}

这是在WidgetProvider类中:

And this in the WidgetProvider class:

public class CounterWidgetProvider extends AppWidgetProvider {
@Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        Intent intent = new Intent(context, CounterWidgetProvider.class);
        context.startService(intent);
    }
}


推荐答案

来自在我自己的三星设备上测试,似乎问题是,如果结果 Intent 没有附加App Widget ID,TouchWiz就会窒息,即使它是 RESULT_CANCELLED

From testing on my own Samsung devices, it seems the problem is that TouchWiz chokes if the result Intent doesn't have the App Widget ID attached, even if it's RESULT_CANCELLED.

来自 App Widget开发者页面



  • App Widget主机调用配置Activity,配置Activity应始终返回结果。结果应该包括启动Activity的Intent传递的App Widget ID(保存在Intent extras中 EXTRA_APPWIDGET_ID )。

  • The App Widget host calls the configuration Activity and the configuration Activity should always return a result. The result should include the App Widget ID passed by the Intent that launched the Activity (saved in the Intent extras as EXTRA_APPWIDGET_ID).

目前还不清楚你究竟是怎么回事希望最终处理结果,但是如果用户退出配置<$ cc,那么在 onCreate()中设置有效结果肯定是个好主意。 C $ C>活性。例如:

It's unclear how exactly you wish to ultimately handle the result, but it's definitely a good idea to go ahead and set a valid result in onCreate(), in case the user backs out of the configuration Activity. For example:

final int id = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
final Intent result = new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
setResult(RESULT_OK, result);

这篇关于Android - Samsung:使用配置活动创建Widget失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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