`
sunting_bcwl
  • 浏览: 94306 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android ContactContacts StreamItem

阅读更多
         Contact
            |
        RawContact
           /  \
          /    \
       Data   StreamItem
                 |
             StreamItemPhoto

Android通讯录中数据库表关系如上所示,一条rawContact关联多条streamItem数据,但是数量是有限制的,可以使用如下方法查询:
int maxLength = 0;
Cursor c = getContentResolver().query(StreamItems.CONTENT_LIMIT_URI,
new String[] { StreamItems.MAX_ITEMS }, null, null, null);

try {
c.moveToFirst();
maxLength = c.getInt(0);
} finally {
c.close();
}


那么如何添加StreamItem呢

private static void addContactStreamItem(Context context, long rawContactId, String text, String comments, long timestamp, String accountName, String accountType){ ContentValues values = new ContentValues(); values.put(StreamItems.RAW_CONTACT_ID, rawContactId); values.put(StreamItems.TEXT, "Breakfasted at Tiffanys"); values.put(StreamItems.TIMESTAMP, timestamp); values.put(StreamItems.COMMENTS, comments); values.put(StreamItems.ACCOUNT_NAME, accountName); values.put(StreamItems.ACCOUNT_TYPE, accountType); context.getContentResolver().insert(StreamItems.CO NTENT_URI, values); }You can also specify an action that should be executed when a stream item or one of its photos is tapped. To achieve this, specify the receiving Activities in your contacts.xml using the tags viewStreamItemActivity and viewStreamItemPhotoActivity:

pictures were written using a ContentValues object, just like all the other data rows of the raw contact. While this approach is still supported, it might fail when used with bigger pictures, as there is a size limit when sending ContentValues across process boundaries. The prefered way now is to use an AssetFileDescriptor and write them using a FileOutputStream instead:


private static void saveBitmapToRawContact(Context context, long rawContactId, byte[] photo) throws IOException { Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI , rawContactId); Uri outputFileUri = Uri.withAppendedPath(rawContactUri, RawContacts.DisplayPhoto.CONTENT_DIRECTORY); AssetFileDescriptor descriptor = context.getContentResolver().openAssetFileDescript or( outputFileUri, "rw"); FileOutputStream stream = descriptor.createOutputStream(); try { stream.write(photo); } finally { stream.close(); descriptor.close(); } }For best results, store uncompressed square photos and let the contacts provider take care of compressing the photo. It will create both a thumbnail and a display photo as necessary.
This API is available on API version 14+. For older versions, we recommend to fallback to the old method using ContentValues and assuming a constant size of 96x96.

http://android-developers.blogspot.com/2012/02/new-social-apis-in-android-ics.html
分享到:
评论

相关推荐

    Android框架揭秘.pdf

    《Android框架揭秘》通过对Android系统源代码的分析,主要介绍Android框架的初始化过程及主要组件的工作原理。作者直接分析和整理了Android框架的主要源代码,并详细讲解了理解框架工作原理所需的各种基础知识和构成...

    Android BLE蓝牙例子(包括android版Lightblue)实例源码

    源码里面有Bluetooth4_3/BLEDemo/Android_Lightblue.apk三个.前两个是BLE的demo。BLEDemo这个功能较Bluetooth4_3多一些,有兴趣的可以都看下。Android_Lightblue.apk是Android版的lightblue,在进行ble开发的时候用...

    Android 7.1.1 (API 25) SDK Platform 下载

    # mv /opt/android-sdk/platforms/android-25/android-7.1.1/* /opt/android-sdk/platforms/android-25/ # rm -rf /opt/android-sdk/platforms/android-25/android-7.1.1 官网下载地址:...

    android应用开发范例精解

    第2篇为应用开发篇,通过实例介绍了Android UI布局、Android人机界面、手机硬件设备的使用、Android本地存储系统、Android中的数据库、多线程设计、Android传感器、Android游戏开发基础、Android与Internet,以及...

    Android串口通信(Android Studio)

    Android串口通信(Android Studio) serial Port 简单的demo 好久之前整的

    Android 8.0.0 (API 26) SDK Platform

    使用: export ANDROID_HOME="/opt/android-...# mv /opt/android-sdk/platforms/android-8.0.0 /opt/android-sdk/platforms/android-26 官网下载地址:https://dl.google.com/android/repository/platform-26_r01.zip

    Android扫雷游戏(基于Android Studio)

    基于Android平台的扫雷小游戏,使用Android Studio开发,附有简单注释,适用于初步掌握Android技术的程序猿们!

    Android Studio实战 快速、高效地构建Android应用

    《Android Studio实战 快速、高效地构建Android应用 全面涵盖关于Android Studio及其庞大工具生态系统的内容,包括Git和Gradle:除了介绍Android Studio与Git(用于源代码管理)和Gradle(一款构建及测试工具)的无缝...

    JS调用Android方法,向Android方法传递json数据

    JavaScript调用Android方法,向Android方法传递json数据。

    c#开发Android应用实战

    《C#开发Android应用实战——使用Mono for Android和.NET/C# 全面透彻地讲解Android应用编程知识,分析如何结合使用C#和Mono来编写在Android设备系列上运行的应用程序。在这本由多位专家联袂撰写的必备精品书籍的...

    WebRTC的Android实现 源码下载 包括服务器,pc端,android端

    WebRTC的Android实现:包括服务器,pc端,android端

    Android平台开发之旅(第2版).pdf

    《Android平台开发之旅(第2版)》涵盖Android 3/4的新特性,立足实际的开发案例,介绍了Android平台开发的基础概念、实用技术和应用模式。主要内容包括应用程序框架、高级界面、数据库应用、网络通信与Web开发、无线...

    Android组件设计思想

    Android应用开发的哲学是把一切都看作是组件。把应用程序组件化的好处是降低模块间的耦合性,同时提高模块的复用性。Android的组件设计思想与传统的组件设计思想最大的区别在于,前者不依赖于进程。也就是说,进程...

    android开发期末大作业.zip

    android开发期末大作业(项目源码,任务书,实验大报告,apk文件) 大作业的要求和内容:(包括题目选择范围、技术要求、递交时间、考核方法等) 一、实验项目名称 Android手机应用开发课程大作业 二、实验目的 1....

    Android 平板电脑应用开发入门经典

    Android 3将Android的全部力量带到了平板计算平台!《Android平板电脑应用开发入门经典》向Android新手快速介绍了如何使用Android 3开发平板应用。经验丰富的作者Wei-Meng Lee首先介绍了如何安装必要的工具并编写...

    android studio 4.2.2 免安装解压版

    android studio 4.2.2 免安装解压版

    Android40个经典源码

    1 Android PDF 阅读器源码 2 Android Txt文本阅读器源码 3 Android SqliteManager 源码 4 Android 个人记账程序源码 5 android 多点触控实例源码 6 android 画图程序 7 Android 手电筒源码 8 Android 天气预报加...

    Android support.v7包

    Android support.v7包

Global site tag (gtag.js) - Google Analytics