c0dehunter
c0dehunter

Reputation: 6160

How to get widget name (provider) in Widget Config Activity?

I have Small and Big widget, both are configured through the same WidgetConfigActivity. Excerpt from AndroidManifest:

    <receiver
        android:name=".SmallWidgetProvider"
        android:icon="@drawable/small_widget_icon"
        android:label="@string/small_widget">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>

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

    <receiver
        android:name=".BigWidgetProvider"
        android:icon="@drawable/big_widget_icon"
        android:label="@string/big_widget">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>

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

widget_small_info.xml:

<appwidget-provider
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:initialLayout="@layout/widget_small_layout"
    android:minHeight="40dp"
    android:minWidth="40dp"
    android:previewImage="@drawable/widget_small_preview"
    android:updatePeriodMillis="1200000"
    android:configure="com.a.b.WidgetConfigActivity">

</appwidget-provider>

I know how to get ID of the widget, but this does not tell me what kind of widget it is:

    Bundle extras = intent.getExtras();
    if (extras != null) {
        mAppWidgetId = extras.getInt(
                AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
    }

How can I differentiate between Small and Big widget in WidgetConfigActivity? I think I should check for provider (Doc: This field corresponds to the android:name attribute in the element in the AndroidManifest.xml file.) with

AppWidgetManager.EXTRA_APPWIDGET_PROVIDER

But this is not in the extras.

Upvotes: 3

Views: 915

Answers (2)

c0dehunter
c0dehunter

Reputation: 6160

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
AppWidgetProviderInfo providerInfo = appWidgetManager.getAppWidgetInfo(mAppWidgetId);

Found this from this answer.

Upvotes: 1

manivanna perumal
manivanna perumal

Reputation: 104

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); AppWidgetProviderInfo appWidgetManager.getAppWidgetInfo(widgetid);

Upvotes: 0

Related Questions