How can I restore data from instant app to installed app?

牧云@^-^@ 提交于 2019-12-12 04:15:52

问题


Keep user state after app installation

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

I want to use the data stored in instant app, after installation full app.
Does anyone know it?


回答1:


UPDATE They’ve again updated the Instant Apps FAQ on how to do this.

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.

For Oreo 8.0 and higher, it should be automatically handled.

But for 7.0 and below, you've got 2 options (#1 is recommended):

  1. PackageManagerCompat#setInstantAppCookie(), the cookie has a size limit, but it is the simplest and most suitable for shared preferences.
  2. InstantAppsClient#getInstantAppData(), creates a ZIP of the data that you'll have to extract and parse once it's moved over to the installed-app side, a bit more complicated.

The FAQ lists a sample for each option:

  • googlesamples/android-instant-apps/cookie-api
  • googlesamples/android-instant-apps/storage-api

The Storage API/ZIP sample does not show you how to parse the ZIP files and what file type/format to expect from SharedPreferences files, so you'll have to implement that yourself, but here are some related posts:

  • How to read file from ZIP using InputStream?
  • How to transfer sharedpreferences file from internal storage to external storage?


来源:https://stackoverflow.com/questions/45275041/how-can-i-restore-data-from-instant-app-to-installed-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!