I created an app that downloads a .sqlite file from url and works with it.
I don’t have problems in dowloading it directly in the database folder.
Once I modified it I would like to upload it to the same url, but I can’t afford to do it.
This is how I download it:
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
try {
URL url = new URL(<url where the sqlite file is>);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Content-Type", "application/x-sqlite3");
urlConnection.setRequestMethod("GET");
urlConnection.connect();
String DatbasesPath = Environment.getDataDirectory() + "/data/" + getApplication().getPackageName() + "/databases/";
File file = new File(DatbasesPath, <database_name>);
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
fileOutput.write(buffer, 0, bufferLength);
}
fileOutput.close();
} catch (IOException e) {
e.printStackTrace();
}
Intent i = new Intent(Start.this, Home.class);
startActivity(i);
finish();
}
}, timeout);
where timeout is the time I want the splash screen to show before starting the app.
How can I upload the file to the same url?
I tried to look around but nothing seems to work!
Thank you!
vittorio ferretti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.