Hi guys please forgive me for my english, I am working as a volunteer(I am newbie) in small project and I have one task to do, It is about SQLite database in android and i feel pretty lost :( Basically i had to download file(image) save it to a folder, and if size of desination folder is above 50MB then i have to keep deleting lastmodifed files(from that folder ofc) until 'size of the destination folder' will be again < 50MB. It was pretty simple every single function works pretty good, but now I have to correct my code, and instead of saving date to a folder i have to put it into SQLite Database. Have you got any ideas how to do this, i think i dont understand Databases idea very well ;/ By storing files into SQLite database do I put real files into database file?(in that case images from URL), or do I store only information about stored file(like date of last modification).
Please help if You can.
Here it is simple download method which I am using,
public static byte[] download(Context context, String adress) {
byte[] image = new byte[2048];
//Downloading an image
if (Patterns.WEB_URL.matcher(adress.toString().trim()).matches()) {
try {
urlad = new URL(adress.trim());
filename = Uri.parse(adress.toString()).getLastPathSegment();
outputFile = new File(filePathFolder, filename);
InputStream is = urlad.openStream();
OutputStream os = new FileOutputStream(outputFile);
int ImageLength;
while ((ImageLength = is.read(image)) != -1) {
os.write(image, 0, ImageLength);
}
is.close();
os.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} else {
Toast.makeText(context.getApplicationContext(), "Please insert valid url adress", Toast.LENGTH_SHORT).show();
}
return image;
}
Aucun commentaire:
Enregistrer un commentaire