I am working on Packages App, Question is How can Update(all data) Data.json (file in Local Storage) with data fetched from Firebase Realtime Database. here is my code
private void UpdateJSONDB()
{
JSONObject JSONobj = null;
try {
loadJSONFromFiles();
//get JSONObject from JSON file
JSONobj = new JSONObject(loadJSONFromFiles());
JSONObject Jazz_SimLagaoOffer = JSONobj.getJSONObject("packages").getJSONObject("jazz_packages").getJSONObject("call_packages").getJSONObject("sim_lagao_offer");
Jazz_SimLagaoOffer.put("onnet", Jazz_SimLagaoOffer_OnNet.toString());
String file = getFilesDir().toString() +"/" + "Data.json";
Toast.makeText(MainActivity.this, file, Toast.LENGTH_SHORT).show();
try {
FileOutputStream fos = new FileOutputStream(file);
if (JSONStringFromFirebase != null) {
fos.write(JSONStringFromFirebase.getBytes());
}
fos.close();
}
catch (FileNotFoundException fileNotFound)
{
Toast.makeText(MainActivity.this, "File not Found", Toast.LENGTH_SHORT).show();
}
catch (IOException ioException)
{
Toast.makeText(MainActivity.this, "IO Exception Occured", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}