App Widget not displaying in ICS app drawer

2020-04-08 10:45发布

问题:

Has anyone experienced their app widget not being listed in the ICS app drawer?

Originally I started this app for FroYo and below, which supports the app widget just fine. Along came Gingerbread and Honeycomb, those work too.

The widget appears in the list in the emulator if I open up the "Widget Preview" app, however when you just open the drawer it isn't listed with the others. It does appear on Honeycomb. I don't (and others haven't also) see it on my Galaxy Nexus anywhere either.

I've tried rebooting as I've seen that solving the problem for some people after initial installation. Also I do have a main activity with the action.MAIN/category.LAUNCHER intent filter since I have app activities, this isn't a widget only type of project.

I'll post some snippets below, let me know if more is needed. My minSdkVersion is at 7 and targetSdkVersion at 15, project properties also has the target checked at 4.0.3. The installLocation attribute is set to auto.

AndroidManifest.xml:

<receiver android:name=".AppWidget" android:label="@string/one_cell_widget_label">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>
    <intent-filter>
        <action android:name="com.frankcalise.h2droid.FORCE_WIDGET_UPDATE" />
    </intent-filter>
    <meta-data
        android:name="android.appwidget.provider"
        android:resource="@xml/one_cell_widget_settings" />
</receiver>

one_cell_widget_settings.xml:

<appwidget-provider
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:initialLayout="@layout/one_cell_widget"
    android:minWidth="@dimen/one_cell_widget"
    android:maxHeight="@dimen/one_cell_widget"
    android:updatePeriodMillis="0" >
</appwidget-provider>

one_cell_widget.xml:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget_background"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/widget_margin"
    android:background="@drawable/widget_background">
    <TextView
        android:id="@+id/widget_title_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_name"
        android:textColor="@android:color/black" />
    <TextView
        android:id="@+id/widget_amount_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/default_widget_amount"
        android:textSize="12sp"
        android:textColor="@color/amount_color" />
    <TextView
        android:id="@+id/widget_percent_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/default_widget_percent" />
</LinearLayout>

and then obviously I implemented the class in AppWidget.java

public class AppWidget extends AppWidgetProvider

UPDATE:

An important logcat message I found earlier today which helped me solve the issue:

06-01 14:41:31.606: E/AppsCustomizePagedView(199): Widget ComponentInfo{com.frankcalise.h2droid/com.frankcalise.h2droid.AppWidget} has invalid dimensions (108, 0)

回答1:

I found the issue. My appwidget-provider element has a typo in one of the attributes, it should say "minHeight", not "maxHeight".

What lead me to finding this was finding an error output in logcat from the launcher. It mentioned my widget had invalid dimensions (therefore it didn't add it to the list of widgets). So then I started checking all the dimension attributes related to my widget.