如果想通讯录进入详情页,那么最重要的参数就是contactId,这个是联系人的唯一标识

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

   @Override

   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

      try {

         Cursor cursor = (Cursor) getListAdapter().getItem(position);

         if (cursor == null) {

            return;

         }

 

         int contactId = cursor.getInt(Personal.ID_COLUMN_INDEX);

         Intent intent = new Intent();

         intent.setClass(ContactsList.this, ContactDetail.class);

         intent.putExtra("contactId",contactId);

         startActivity(intent);

      }catch(Exception ex) {

         ex.printStackTrace();

      }

   }

});

本地通讯录的原图获取方法是:

>注‘Android技术交流群878873098,欢迎大家加入交流,畅谈!本群有免费学习资料视频且免费分享

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

public class ContactDetail extends Activity {

 

    private ImageView contact_photo;

 

    public static void startActivity(Context context) {

        Intent intent = new Intent();

        intent.setClass(context,ContactDetail.class);

        context.startActivity(intent);

    }

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.contact_detail);

 

        int contactId = getIntent().getIntExtra("contactId"0);

 

        contact_photo = (ImageView)findViewById(R.id.contact_photo);

 

        loadTask task = new loadTask(contactId);

        task.execute();

 

    }

 

 

    private class loadTask extends AsyncTask {

 

        public loadTask(int id) {

            contactId = id;

        }

        private int contactId;

 

        @Override

        protected Bitmap doInBackground(Void... params) {

            InputStream inputStream = openDisplayPhoto(contactId);

 

            BitmapFactory.Options opt = new BitmapFactory.Options();

            opt.inSampleSize = 1;

            Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, opt);

            return bitmap;

        }

 

        @Override

        protected void onPostExecute(Bitmap result) {

 

            if(result != null) {

                contact_photo.setImageBitmap(result);

            }

            super.onPostExecute(result);

        }

 

    }

 

    /**

     * 这个是取到清晰图的inputStream的代码

     * @param contactId

     * @return

     */

    public InputStream openDisplayPhoto(long contactId) {

        Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);

        Uri displayPhotoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);

        try {

            AssetFileDescriptor fd =

                    this.getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");

            return fd.createInputStream();

        catch (IOException e) {

            e.printStackTrace();

            return null;

        }

    }

 

}

activity的运行效果是:

>注‘Android技术交流群878873098,欢迎大家加入交流,畅谈!本群有免费学习资料视频且免费分享

android如何取得本地通讯录的头像的原图_第1张图片


 

更多相关文章

  1. android 2.2 通讯录
  2. Android 2.1读取手机通讯录
  3. android 通讯录的相关操作
  4. Android大图片之缩略图,以及对原图按照指定宽高裁剪成缩略图
  5. android获取通讯录
  6. android 向系统通讯录添加一个联系人信息
  7. android获取手机的所有通讯录的号码和sim卡号码
  8. Android通过ContentProvider往通讯录添加联系人和获取联系人
  9. android 获取通讯录并显示listview

随机推荐

  1. Android-AbsoluteLayout(绝对布局)
  2. Android 之shape 的用法介绍
  3. Android(安卓)数据存储ContentProvider(类
  4. Android常用第三方框架
  5. Android(安卓)中的观察者模式Observer
  6. Android(安卓)初学者第一步 Activity生命
  7. 安装Android的Eclipse插件ADT遇到错误“r
  8. 【Android】Android Theme的设置
  9. [Android Pro] Android 打包流程
  10. TextView 加链接所有方法