Android(安卓)数据存储机制
一、Android数据存储机制
- 使用SharedPreferences存储数据;
- 文件存储数据;
- SQLite数据库存储数据;
- 使用ContentProvider存储数据;
- 网络存储数据;
二、如何访问彩信中附加内容
1.使用content provider访问附加内容;
2.访问视频/音频附件;
private static final int RAW_DATA_BLOCK_SIZE = 16384; //Set the block size used to write a ByteArrayOutputStream to byte[] public static final int ERROR_IO_EXCEPTION = 1; public static final int ERROR_FILE_NOT_FOUND = 2; public static byte[] LoadRaw(Context context, Uri uri, int Error){ InputStream inputStream = null; byte[] ret = new byte[0]; //Open inputStream from the specified URI try { inputStream = context.getContentResolver().openInputStream(uri); //Try read from the InputStream if(inputStream!=null) ret = InputStreamToByteArray(inputStream); } catch (FileNotFoundException e1) { Error = ERROR_FILE_NOT_FOUND; } catch (IOException e) { Error = ERROR_IO_EXCEPTION; } finally{ if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { //Problem on closing stream. //The return state does not change. Error = ERROR_IO_EXCEPTION; } } } //Return return ret; } //Create a byte array from an open inputStream. Read blocks of RAW_DATA_BLOCK_SIZE byte private static byte[] InputStreamToByteArray(InputStream inputStream) throws IOException{ ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[RAW_DATA_BLOCK_SIZE]; while ((nRead = inputStream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); return buffer.toByteArray(); }
更多相关文章
- SpringBoot 2.0 中 HikariCP 数据库连接池原理解析
- 一句话锁定MySQL数据占用元凶
- Android(安卓)Socket服务器 Servlet服务器
- Android开发之ClipboardManager
- Android数据的四种存储方式之一——总览
- Android(安卓)KK上对ALC5616调试笔记——音量调节
- android 使用SimpleCursorAdapter将SQLite数据显示到ListView
- Android快速开发框架dyh详解(四)---数据层的使用
- 2.4 Android中的IPC方式(三)