在我的应用程序中,我想从URL
下载图像,然后将它们保存在Android
设备的安全区域中。但我不知道Android
中的存储选项。我不想使用sdcard
或其他外部存储空间。
答案 0 :(得分:1)
虽然将应用程序数据保存在设备的有限内部存储中并不是一个好习惯,但您可以这样做。
查看官方谷歌文档,以便在内部设备存储中保存数据,这将使您能够在内部存储内容。
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
答案 1 :(得分:0)
然后,您可以转换图像>位图> ToBytes然后进入Base64 String对象。通过这种方式,您将获得Image的String表示,您只需将其存储到SQLlite DB中即可。
Warnig:这可能会失去图像质量。
将drawable转换为Base64字符串。
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
imgString = Base64.encodeBytes(b);
将String转换回drawable。从SQLite DB获取字符串,然后
byte[] b = Base64.decode(imgString);
Bitmap bc = BitmapFactory.decodeByteArray(b, 0, b.length);
Drawlable drawabe = new BitmapDrawable(bc).getCurrent();
答案 2 :(得分:0)
使用内部存储http://developer.android.com/guide/topics/data/data-storage.html#filesInternal并强制应用安装在内部http://developer.android.com/guide/topics/manifest/manifest-element.html#install
非root设备上的应该足够......
答案 3 :(得分:0)
我想这可能对你有用(就像我一样):https://github.com/thest1/LazyList