我和AppWidgetManager::requestPinAppWidget有点问题
有时,方法requestPinAppWidget会返回false。我们通过卸载应用程序并使用android studio从fresh重新安装来重现它。我们可以使用以下代码在三星和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。
为什么会这样呢?我如何减轻它?或者至少提前知道,这样我就不会向用户展示流程的其余部分
发布于 2019-06-04 23:40:34
这是由于WidgetActionsReceiver在默认情况下处于禁用状态。当使用功能标志启用它时,更改需要一段时间才能到达启动器。
https://stackoverflow.com/questions/56431994
复制相似问题