未调用RemoteViewsService onGetViewFactory

问题描述 投票:0回答:1

我确定我在这里遗漏了一些简单的东西但是在尝试填充StackWidget时onGetViewFactory没有调用。我已经多次这样做了,找不到我的错误。

RemoteViews正在updateWidget中附加:

public static void updateWidget(Context context, AppWidgetManager appWidgetManager, int widgetId) {
    // Create the RemoteViews to represent the widget layout.
    Log.i(TAG, "updateWidget: Creating RemoteViews");
    RemoteViews widgetViews = new RemoteViews(context.getPackageName(), R.layout.stack_widget_layout);

    // Create an intent that points to our widget service.
    Log.i(TAG, "updateWidget: Creating Intent");

    Intent remoteIntent = new Intent(context, StackWidgetService.class);

    // Attach that intent to the RemoteViews as our remote adapter.
    Log.i(TAG, "updateWidget: Setting Adapter");
    widgetViews.setRemoteAdapter(R.id.stack_view, remoteIntent);

    // Set which view should be used as the empty view.
    Log.i(TAG, "updateWidget: Setting empty view");
    widgetViews.setEmptyView(R.id.stack_view, R.id.text_empty);

    // Update the widget.
    Log.i(TAG, "updateWidget: Updating widget");
    appWidgetManager.updateAppWidget(widgetId, widgetViews);
}

调用appWidgetManager.updateAppWidget后应调用以下内容,但不是:

 @Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
    // NOT CALLED
    Log.i(TAG, "onGetViewFactory: Creating new view factory");
    return new StackWidgetViewFactory(getApplicationContext());
}

据我所知,我的清单是正确的:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver android:name=".stackwidget.StackWidgetProvider"
        android:exported="true">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>

        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/stack_widget_info" />
    </receiver>

    <service android:name=".stackwidget.StackWidgetService"
        android:exported="true"
        android:permission="android.permission.BIND_REMOTEVIEWS"/>

</application>

这是我的stack_widget_info.xml,为了安全起见:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="250dp"
    android:minHeight="180dp"
    android:updatePeriodMillis="1800000"
    android:initialLayout="@layout/stack_widget_layout"
    android:autoAdvanceViewId="@layout/stack_item"
    android:widgetCategory="home_screen"
    android:resizeMode="horizontal |vertical">

</appwidget-provider>
android widget uistackview
1个回答
0
投票

问题实际上是在我的小部件布局中。约束布局导致问题。在切换到线性布局时,它可以正确运行。

© www.soinside.com 2019 - 2024. All rights reserved.