gpt4 book ai didi

android - 如何将即时应用程序中的数据恢复到已安装的应用程序?

转载 作者:行者123 更新时间:2023-12-05 00:21:34 26 4
gpt4 key购买 nike

应用安装后保持用户状态

https://developer.android.com/topic/instant-apps/ux-best-practices.html#keep_user_state_after_app_installation

我想在安装完整应用程序后使用存储在即时应用程序中的数据。
有人知道吗?

最佳答案

更新 他们再次更新了 Instant Apps FAQ关于如何做到这一点。

For devices running Android 8.0 (API level 26) or higher, the instant app's data is transferred automatically when the APK installation begins, if the installed app is configured to use targetSandboxVersion 2.

For installed apps not configured to use targetSandboxVersion 2, or devices running Android 7.1 (API level 25) or lower, please consider using the Cookie API (Sample) or Storage API (Sample) to transfer the data.



对于 Oreo 8.0 及更高版本,应自动处理。

但对于 7.0 及以下版本,您有 2 个选项(推荐使用#1):
  • PackageManagerCompat#setInstantAppCookie() , cookie 有大小限制,但它是最简单最适合共享偏好的。
  • InstantAppsClient#getInstantAppData() ,创建数据的 ZIP,一旦将其移动到已安装的应用程序端,您就必须提取和解析它,这有点复杂。

  • 常见问题解答列出了每个选项的示例:
  • googlesamples/android-instant-apps/cookie-api
  • googlesamples/android-instant-apps/storage-api

  • Storage API/ZIP 示例没有向您展示如何解析 ZIP 文件以及从 SharedPreferences 文件中期望的文件类型/格式,因此您必须自己实现,但这里有一些相关的帖子:
  • How to read file from ZIP using InputStream?
  • How to transfer sharedpreferences file from internal storage to external storage?
  • 关于android - 如何将即时应用程序中的数据恢复到已安装的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45275041/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com