【发布时间】:2019-10-19 06:46:17
【问题描述】:
我遇到了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。
这是为什么呢?我怎样才能减轻它?或者至少提前知道,所以我不会向用户展示其余的流程
【问题讨论】:
标签: android android-widget samsung-mobile android-8.0-oreo