Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a widget to the Android home screen from my app?

Tags:

I'm writing an application which should be able to add widgets (just text boxes) to the home screen of the user's phone when the user instructs my app to do so. How can I do such a thing?

I know that I can add an app widget but how about adding more?

like image 742
Adam Arold Avatar asked Apr 19 '13 08:04

Adam Arold


2 Answers

This was answered a long time ago, but in case anyone stumbles upon this question I thought I should provide an up-to-date answer.

As of Android O (API 26), you can now pin widgets to the user's launcher from your app!

Simply create the widget in your app's AndroidManifest file and use AppWidgetManager to request that the widget be pinned to the launcher. Note that it is up to the launcher to support this feature, so you must call AppWidgetManager's isRequestPinAppWidgetSupported() method before requesting to pin it.

Here's some documentation from Google that goes into more detail: https://developer.android.com/preview/features/pinning-shortcuts-widgets.html#widgets

Hope this helps!

Edit: It looks like the documentation pages have changed since I posted this answer. Here is a more helpful link that gives a code example of how to pin a widget to a launcher: https://developer.android.com/guide/topics/appwidgets/#Pinning

like image 26
DalvikDroid Avatar answered Oct 05 '22 08:10

DalvikDroid


It is not possible from a app to place a widget in the home screen. Only the home screen can add app widgets to the home screen.

similar links link1, link2, link3

But you can offer user to pick widget from widgetpicker.

    Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
    pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetID);
    startActivityForResult(pickIntent, KEY_CODE);
like image 177
stinepike Avatar answered Oct 05 '22 06:10

stinepike