【问题标题】:ShortcutManager crash in instant apps即时应用程序中的 ShortcutManager 崩溃
【发布时间】:2020-01-07 18:19:33
【问题描述】:

当我运行我的即时应用程序时,由于快捷方式功能而崩溃,请查看带有堆栈跟踪的图像,这是我唯一可以提供的,因为我无法附加调试器,另一个问题:(

**GroupApplication.class**
override fun onCreate() {
    ...
    ShortcutsHelper.init(this)
    ShortcutsHelper.addSearchShortcut()
}
object ShortcutsHelper {
    lateinit var appContext: Context
    lateinit var shortcutManager: ShortcutManager

    fun init(context: Context) {
        this.appContext = context.applicationContext
        this.shortcutManager = context.getSystemService(ShortcutManager::class.java)
    }

    fun addSearchShortcut() {
        val shortcut = ShortcutInfo.Builder(appContext, SEARCH_SHORTCUT_ID)
                .setShortLabel(appContext.getString(R.string.search_shortcut_short_label))
                .setLongLabel(appContext.getString(R.string.search_shortcut_long_label))
                .setIcon(Icon.createWithResource(appContext, R.drawable.ic_search_black))
                .setIntent(GroupHomeActivity.getStartIntent(appContext, NavigationScreen.SEARCH))
                .build()

        shortcutManager.addDynamicShortcuts(listOf(shortcut))
    }

我知道快捷方式在 Instant App 中没有任何意义,有没有比在创建 IA 时注释所有与快捷方式相关的代码更好的解决方案?

【问题讨论】:

    标签: android kotlin android-instant-apps android-shortcut


    【解决方案1】:

    我知道快捷方式在 Instant App 中没有任何意义,有没有比拥有所有相关代码更好的解决方案 创建 IA 时评论的快捷方式?

    所以是的,出于安全目的,Instant Apps 被限制运行某些 API。曾经有一个FAQ页面表明这一点,但我找不到了。

    但无论如何,您不必将其注释掉。您可以使用:

    /instantapps/PackageManagerCompat.html#isInstantApp()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-07
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多