0

I tried to search this question everywhere. I want to know what are the different ways as a programmer we can add widgets on the homescreen. As a user we can go into the widgets menu and drag drop the widgets shown. I also found a method to show widget chooser and the chooser appers on the screen but it has no action. Following is the chooser intent code :

 Intent getwidgetidintent = new Intent();
        int appwidgetid = getwidgetidintent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID);
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,appwidgetid);
        startActivity(intent);

But this only shows a chooser, when i click on a widget it doesn't work at all.

I want to add the widget on the homescreen as soon as the app is installed or some button in the setting of the app. Firstly Is this possible? And if it is not possible then what is the reason behind it i am not able to understand it?

1
  • Please can you give an explaination why you gave down vote to this question? Jan 29, 2016 at 13:23

1 Answer 1

2

But this only shows a chooser, when i click on a widget it doesn't work at all.

ACTION_APPWIDGET_PICK is for use by a home screen or other AppWidgetHost, as is covered by the documentation. You are not implementing either of those.

Firstly Is this possible?

No.

what is the reason behind it i am not able to understand it?

First, not all home screens support app widgets.

Second, not all users will want your app widget, so forcing an app widget on the user "as soon as the app is installed" would be a hostile act.

Third, the user has to indicate where on the home screen the app widget would go, and that can only be handled by the home screen, as only the home screen knows where the app widget can fit and so forth.

Fourth, with respect to "as soon as the app is installed", your app will not execute any code until the user indicates that she wants to work with your app, whether by installing your app widget or launching your app from a home screen launcher icon. This is to help prevent "drive-by malware" and related attacks.

1
  • So programmatically we cannot add the widget through any application . Thank you so much, I have one more question related widgets, i will raise the question soon as we cannot raise questions consequently. Jan 29, 2016 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.