I have built a android widget that allows for multiple sizes 2×2 and 4×2. So when someone is on the widget picker screen they see both sizes. They click on one of the sizes and it goes to my configuration activity. How do I know what size they picked on the widget picker screen. I need to know which one was chosen on the configuration activity. I am having trouble of how to move forward and what direction to look into. Below is my manifest file just in case you think it might clarify what I am doing:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.corradodev.customizable_countdown_widget"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="3" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<!-- Configure Activity -->
<activity android:name=".configure">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<!-- Broadcast Receivers that will process AppWidget updates -->
<receiver android:name=".customizable_countdown_widget_large" android:label="@string/app_name_large">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_provider_large" />
</receiver>
<receiver android:name=".customizable_countdown_widget_small" android:label="@string/app_name_small">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_provider_small" />
</receiver>
<!-- Service for updating -->
<service android:name=".widget_service" />
</application>
</manifest>
Thanks for any help.
Solution:
In the oncreate of the configure activity
Bundle mExtras = mIntent.getExtras();
if (mExtras != null) {
mAppWidgetId = mExtras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
//Log.d(TAG, Integer.toString(mAppWidgetId));
// If they gave us an intent without the widget id, close
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
AppWidgetProviderInfo providerInfo = AppWidgetManager.getInstance(getBaseContext()).getAppWidgetInfo(mAppWidgetId);
String minWidth=String.valueOf(providerInfo.minWidth);
You could probably use
AppWidgetProviderInfo AppWidgetManager.getAppWidgetInfo(int appWidgetId)and check `minSize’, etc. once you have the wdiget ID. You can get it from the config activity like this: