我在使用 AppWidgetManager::requestPinAppWidget
时遇到问题
有时 requestPinAppWidget
方法返回 false。我们通过卸载应用程序并使用 android studio 重新安装来重现它。我们可以使用以下代码在 Samsung 和 Pixel 设备上一致地重现它:
@RequiresApi(Build.VERSION_CODES.O)
private fun showWidgetAddingActivity(context: Context) {
val appWidgetManager = context.applicationContext.getSystemService(AppWidgetManager::class.java)
val myProvider = ComponentName(context.applicationContext, WidgetActionsReceiver::class.java)
val launcherSupported = appWidgetManager.requestPinAppWidget(myProvider,null, null)
}
launcherSupported
的值将为 false
如果我们在全新安装后(或在几分钟后)运行它。在任何其他情况下它将是 true
发生这种情况时调用 appWidgetManager.isRequestPinAppWidgetSupported 总是返回 true。
这是为什么呢?我怎样才能减轻它?或者至少提前知道它,这样我就不会向用户展示流程的其余部分
最佳答案
这是由于默认情况下禁用 WidgetActionsReceiver
引起的。当使用功能标志启用它时,更改到达启动器需要一些时间。
关于最近安装后 Android requestPinAppWidget 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56431994/