Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open launcher's widget picker?

I want to open the launcher's widget picker (for example, the one we get when we long press on home screen) from my Activity. What I want to achieve is, I want to take the user to my widget so that there are more chances that he will consider adding it.

Programmatically adding the widget to home screen will be the best case. But, because that is not possible, I want to go as closer as possible to make user add the widget.

I tried the following but that only opens a dialog (not the launcher's) with all the widgets and by selecting one nothing happens.

Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, 0);
startActivityForResult(pickIntent, 1234);

How to make this work? Any suggestions on this scenario are much appreciated.

like image 645
Mangesh Avatar asked Mar 04 '16 17:03

Mangesh


People also ask

Where are widgets in Nova launcher?

First, long-press on the home screen and then swipe up from the bottom of the screen to access "Widgets." Then Nova Actions > App Drawer. This will add an app drawer button to the home screen which you can then place in the dock.

Where are my widgets?

Find a Space First, touch and hold an open space on your home screen. You'll see an option at the bottom of the screen to view the widgets drawer. Where they dwell until summoned for duty.

What is a widget picker?

Picker is a widget showing multiple customized PickerColumn s. The PickerColumns are initialized in setColumns . Call setColumnAt if the column value range or labels change. Call setColumnValue to update the current value of PickerColumn.


1 Answers

It's possible to pin widget to homescreen (official doc) on API 26+:

AppWidgetManager mAppWidgetManager =
context.getSystemService(AppWidgetManager.class);

AppWidgetProviderInfo myWidgetProviderInfo = new AppWidgetProviderInfo();
ComponentName myProvider = myWidgetProviderInfo.provider;

if (mAppWidgetManager.isRequestPinAppWidgetSupported()) {
   Intent pinnedWidgetCallbackIntent = new Intent( ... );
   PendingIntent successCallback = PendingIntent.createBroadcast(context, 0,pinnedWidgetCallbackIntent);

   mAppWidgetManager.requestPinAppWidget(myProvider, null,
       successCallback.getIntentSender());
}
like image 135
HeyAlex Avatar answered Oct 13 '22 04:10

HeyAlex