zoukankan      html  css  js  c++  java
  • 获取联系人名称及全部电话的实例

    CODE:

    String[] projection = new String[]{
                                        People._ID,
                                        People.NAME
                        };
                        
    Uri peopleUri = People.CONTENT_URI;
    Log.d( TAG, "peopleUri: " + peopleUri );
    Cursor peopleCursor = managedQuery( peopleUri, projection, null, null, People.DEFAULT_SORT_ORDER );
                        
    if( peopleCursor == null ){
        Log.e( TAG, "peopleCursor is null");
        return false;
    }
                        
    if( peopleCursor.moveToFirst()){
                                
        boolean isAfterLastPeople = peopleCursor.isAfterLast();
        while( !isAfterLastPeople ){
            String name = peopleCursor.getString(peopleCursor.getColumnIndexOrThrow( People.NAME ));
            Log.d( TAG, "name: " + name );
                                        
            Long personId = peopleCursor.getLong( peopleCursor.getColumnIndexOrThrow(People._ID) );
            Uri personUri = ContentUris.withAppendedId(peopleUri, personId );
            Uri phoneUri  = Uri.withAppendedPath( personUri, People.Phones.CONTENT_DIRECTORY );
            Log.d( TAG, "phoneUri: " + phoneUri );
                                        
            Cursor phoneCursor = managedQuery( phoneUri, null, null, null, People.Phones.DEFAULT_SORT_ORDER );
            if( phoneCursor == null ){
                Log.e( TAG, "phoneCursor is null");
                return false;
            }
                
            if( phoneCursor.moveToFirst()){
                boolean isAfterLastPhone = phoneCursor.isAfterLast();
               while( !isAfterLastPhone ){
                  String number  = phoneCursor.getString( phoneCursor.getColumnIndexOrThrow( PhonesColumns.NUMBER));
                  String type    = phoneCursor.getString( phoneCursor.getColumnIndexOrThrow( PhonesColumns.TYPE ));
                                                    
                  Log.d( TAG, "number:" + number );
                  Log.d( TAG, "type:" + type );
                                                
                  phoneCursor.moveToNext();
                  isAfterLastPhone = phoneCursor.isAfterLast();
            }
        }
                                        
        peopleCursor.moveToNext();
        isAfterLastPeople = peopleCursor.isAfterLast();
    }

  • 相关阅读:
    Java web ch02_5
    Java web ch02_4
    Java web ch02_3
    Java web ch02_9
    myeclipse和eclipse的区别以及优越性
    新的学年,迎来新的活力!
    Javaweb中的Tomcat服务器(简单了解)
    一切都是对象
    java中被隐藏的具体实现
    SSL与TLS的区别以及介绍
  • 原文地址:https://www.cnblogs.com/xyzlmn/p/3168263.html
Copyright © 2011-2022 走看看