Set App Widget To Home Screen Programmatically
I want to set my custom app widget to home screen. I have searched a lot and implement code and also run some demo But in all that what happen after click on button widget can't be
Solution 1:
i want that after click on button from my activity widget will be set to home screen without going here
That is not possible.
Solution 2:
As of Android O, In your app, you can create a request for the system to pin a widget onto a supported launcher.
Create the widget in your app's manifest file Call the requestPinAddWidget() method
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AppWidgetManagermAppWidgetManager= getSystemService(AppWidgetManager.class);
ComponentNamemyProvider=newComponentName(AddWidgetActivity.this,
AppWidgetSmall.class);
Bundleb=newBundle();
b.putString("ggg", "ggg");
if (mAppWidgetManager.isRequestPinAppWidgetSupported()) {
IntentpinnedWidgetCallbackIntent=newIntent(AddWidgetActivity.this,
AppWidgetSmall.class);
PendingIntentsuccessCallback=
PendingIntent.getBroadcast(AddWidgetActivity.this, 0,
pinnedWidgetCallbackIntent, 0);
mAppWidgetManager.requestPinAppWidget(myProvider, b, successCallback);
}
}
Post a Comment for "Set App Widget To Home Screen Programmatically"