Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store data in android instant app and restore it in installed app

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"?

like image 872
Stonek Avatar asked Jan 04 '23 16:01

Stonek


2 Answers

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.

like image 189
Mateusz Teteruk Avatar answered Jan 06 '23 05:01

Mateusz Teteruk


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.

like image 36
Julia K Avatar answered Jan 06 '23 05:01

Julia K