I know we can transfer the data from instant app to the full app using the Storage api of Google Instant as mentioned here.
For devices running OS version less than Oreo, I am trying to read the data as follows:
public void getInstantAppData(final Activity activity, final InstantAppDataListener listener) {
InstantApps.getInstantAppsClient(activity)
.getInstantAppData()
.addOnCompleteListener(new OnCompleteListener<ParcelFileDescriptor>() {
@Override
public void onComplete(@NonNull Task<ParcelFileDescriptor> task) {
try {
FileInputStream inputStream = new FileInputStream(task.getResult().getFileDescriptor());
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
ZipInputStream zipInputStream = new ZipInputStream(bufferedInputStream);
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
Log.i("Instant-app", zipEntry.getName());
if (zipEntry.getName().equals("shared_prefs/")) {
extractSharedPrefsFromZip(activity, zipEntry);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
private void extractSharedPrefsFromZip(Activity activity, ZipEntry zipEntry) throws IOException {
File file = new File(activity.getApplicationContext().getFilesDir() + "/shared_prefs.vlp");
mkdirs(file);
FileInputStream fis = new FileInputStream(zipEntry.getName());
BufferedInputStream bis = new BufferedInputStream(fis);
ZipInputStream stream = new ZipInputStream(bis);
byte[] buffer = new byte[2048];
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
int length;
while ((length = stream.read(buffer)) > 0) {
bos.write(buffer, 0, length);
}
}
But I am getting an error Method threw 'java.io.FileNotFoundException' exception.
Basically when I am trying to read the shared_pref file it is not able to locate it. What is the full name of the file and is there any better way to transfer my shared pref data from instant app to installed app.