问题
According to Google druging developing instant apps
"Best practices" is "Keeping user state after app installation"
https://developer.android.com/topic/instant-apps/ux-best-practices.html#keep_user_state_after_app_installation
I tried to use Internal Storage in instant app and installed app, but it doesn't work, because there are different paths:
- instant app: /data/user/0/com.google.android.instantapps.supervisor/files/hosted/package_name/files
- installed app: /data/user/0/package_name/files
Of course, external storage also doesn't work, because instant app could receive permission to it.
Does anybody know or has idea how to resolve that problem, which should be solved according to Google "Best practices"?
回答1:
Storage transfer from instant to installed app happens automatically on O+, but for platforms below O, you need to use this API. Please refer to Android Instant Apps FAQ: “How do I transfer data from an instant app to an installed app?”
https://developer.android.com/topic/instant-apps/faqs.html
For devices running Android 8.0 (API level 26) or higher, the instant app's data is transferred automatically when the APK installation begins. For devices running Android 7.1.1 (API level 25) or lower, call compatibility API in Google Play Services.
回答2:
You can migrate data from InstantApp to installed app using StorageApi, example is here: google sample storage api. Just access
InstantApps.getInstantAppsClient(this).instantAppData
and you have it, addOnSuccessListener
and here you go.
回答3:
The only option I can think of is saving that info on your server somehow and when the user installs the app recover it and continue where he left of. This is something that Google specified for apps with shopping carts (for example), where after the install the user will be able to continue shopping without losing any articles he may have chosen already. Also remember that through SmartLock you can save an account on the device and recover it later in the installed app. Hope this helps!
回答4:
I have been using couchbase lite to save my data on couchdb server then writing a filter then run pullReplication from the server using a sync gateway you can check out how it works here. Then in the android app i use the SharedPreferences to check if its the apps first run then run the sync
来源:https://stackoverflow.com/questions/45456592/how-to-store-data-in-android-instant-app-and-restore-it-in-installed-app