Current Situation
My widget uses a config Activity to Select type of Widget.. So whenever I place my widget (using system launcher), the config activity launches first. It asks for configuring the widget and which is must for my widget. This works well...
Second method to place the widget on Homescreen is using the following code `
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
ComponentName myProvider = new ComponentName(context, ExampleAppWidgetProvider.class);
if (appWidgetManager.isRequestPinAppWidgetSupported()) {
// Create the PendingIntent object only if your app needs to be notified
// that the user allowed the widget to be pinned. Note that, if the pinning
// operation fails, your app isn't notified. This callback receives the ID
// of the newly-pinned widget (EXTRA_APPWIDGET_ID).
PendingIntent successCallback = PendingIntent.getBroadcast(
/* context = */ context,
/* requestCode = */ 0,
/* intent = */ new Intent(...),
/* flags = */ PendingIntent.FLAG_UPDATE_CURRENT);
appWidgetManager.requestPinAppWidget(myProvider, null, successCallback);
}
` Above is from official docs
My code is this
ComponentName mmwidgetProvider = new ComponentName(MainActivity.this, mm_WidgetAppWidgetProvider.class);
if (mAppWidgetManager.isRequestPinAppWidgetSupported()) {
Intent pinnedWidgetCallbackIntent = new Intent(MainActivity.this, mm_WidgetAppWidgetProvider.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0,
pinnedWidgetCallbackIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
mAppWidgetManager.requestPinAppWidget(mmwidgetProvider, null, pendingIntent);
}
The Problem
However the problem is, when I execute this code the widget is placed on the screen but the widgetConfig activity is not launched and so my widget shows nothing. Widget's data totally depends upon the config activity which needs to be initialized eveytime a new widget is placed.
Please is there any way I can use the above code and when I execute it, My widget config activity is launched asking for widget to configured first.
Any help is Greatly Appreciated Thanks in Advance.
This solution worked for me: Try replacing the use of 'getBroadcast' with 'getActivity' and see if it works. Change your pinnedWidgetCallback Intent in your configuration activity.