一、Android数据存储机制

  1. 使用SharedPreferences存储数据;
  2. 文件存储数据;
  3. SQLite数据库存储数据;
  4. 使用ContentProvider存储数据;
  5. 网络存储数据;
注意:Android 中的数据存储都是私有的,其他应用程序都是无法访问的,除非通过ContentResolver获取其他程序共享的数据。


二、如何访问彩信中附加内容

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(); }  

更多相关文章

  1. SpringBoot 2.0 中 HikariCP 数据库连接池原理解析
  2. 一句话锁定MySQL数据占用元凶
  3. Android(安卓)Socket服务器 Servlet服务器
  4. Android开发之ClipboardManager
  5. Android数据的四种存储方式之一——总览
  6. Android(安卓)KK上对ALC5616调试笔记——音量调节
  7. android 使用SimpleCursorAdapter将SQLite数据显示到ListView
  8. Android快速开发框架dyh详解(四)---数据层的使用
  9. 2.4 Android中的IPC方式(三)

随机推荐

  1. Android 布局 之 LinearLayout
  2. android消息机制之二--Handler
  3. android图片压缩的3种方法实例
  4. android api (83) —— InputMethodSessi
  5. Android学习笔记——各种常用布局管理器
  6. Android(安卓)蓝牙开发(四)OPP传输文件
  7. 基于MQTT实现Android消息推送(Push)(2)
  8. android 有关怎么自己添加系统级服务 jav
  9. Android 网络(四) Retrofit学习笔记
  10. Android UI Operation in Thread