Created
November 18, 2020 10:28
-
-
Save waliahimanshu/a90379e0673d36de7097349b4495eddd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun requestWidgetPinning(context: Context) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
val appWidgetManager = AppWidgetManager.getInstance(context) | |
val componentName = ComponentName(context, YourAppWidget::class.java) | |
if (appWidgetManager.isRequestPinAppWidgetSupported) { | |
val pinnedWidgetCallbackIntent = Intent(context, YourAppWidget::class.java) | |
val successCallback = PendingIntent.getBroadcast( | |
context, 0, | |
pinnedWidgetCallbackIntent, 0 | |
) | |
appWidgetManager.requestPinAppWidget(componentName, Bundle(), successCallback) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment