My app allows user to export its data to other users or just to save as backup.
The import/export is working FINE
In order to let the user have a sample data when it first installs my app I want to package some default data. I created the sample data, tested IS WORKING FINE, then i packaged it in assets
folder and load it when user runs the app for first time.
But i'm getting file not found exception
HERE GOES THE CODE:
private List<Giveaway> loadJsonData(Uri data, User user) {
List<Giveaway> result = null;
try {
InputStream is = this.getContentResolver().openInputStream(data);
Gson parser = new GsonBuilder().setDateFormat("dd/MM/yy").setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setLongSerializationPolicy(LongSerializationPolicy.DEFAULT).setLenient().excludeFieldsWithModifiers(Modifier.FINAL, Modifier.STATIC, Modifier.TRANSIENT).create();
Set<Giveaway> temp = new HashSet<Giveaway>(50);
temp.addAll((Collection<? extends Giveaway>) parser.fromJson(new InputStreamReader(is), TypeToken.getParameterized(List.class, Giveaway.class).getType()));
result = new ArrayList<Giveaway>(temp);
} catch (FileNotFoundException e) {
e.printStackTrace();
result = new ArrayList<Giveaway>(1);
}
return result;
}
and I call it using:
loadJsonData(Uri.parse("file:///android_asset/giveaway_export.json"), sampleUser);