如何从设备中再检查一下文件夹名称充分接触可以是可选可选、文件夹、中再、充分

2023-09-07 02:03:24 作者:别动我的小鱼干

您好,我的android开发新的,我与编码挣扎不好......我在动态增长的复选框的名字,让我的设备的完整的联系人列表中哪些可以选择....它必须已经被选中,也将动态增长我已经尝试了很多事情早已但不找到任何答案...我必须获取选中从中联络按钮preSS

 公共无效fetchContacts(){        字符串phoneNumber的= NULL;         LayoutInflater layoutInflater =                  (LayoutInflater)getBaseContext()getSystemService(Context.LAYOUT_INFLATER_SERVICE)。                最后查看addView = layoutInflater.inflate(R.layout.contact,NULL);        乌里CONTENT_URI = ContactsContract.Contacts.CONTENT_URI;        字符串_ID = ContactsContract.Contacts._ID;        字符串DISPLAY_NAME = ContactsContract.Contacts.DISPLAY_NAME;        字符串HAS_PHONE_NUMBER = ContactsContract.Contacts.HAS_PHONE_NUMBER;        乌里PhoneCONTENT_URI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;        字符串Phone_CONTACT_ID = ContactsContract.CommonDataKinds.Phone.CONTACT_ID;        串号= ContactsContract.CommonDataKinds.Phone.NUMBER;        StringBuffer的输出=新的StringBuffer();        ContentResolver的ContentResolver的= getContentResolver();        光标光标= contentResolver.query(CONTENT_URI,NULL,NULL,NULL,NULL);        //循环手机中的每一个接触        如果(cursor.getCount()大于0){            而(cursor.moveToNext()){                串CONTACT_ID = cursor.getString(cursor.getColumnIndex(_ID));                字符串名称= cursor.getString(cursor.getColumnIndex(DISPLAY_NAME));                INT hasPhoneNumber =的Integer.parseInt(cursor.getString(cursor.getColumnIndex(HAS_PHONE_NUMBER)));                如果(hasPhoneNumber大于0){                    output.append(\\ n名称:+姓名);                    //查询及回路接触的每一个电话号码                    光标phoneCursor = contentResolver.query(PhoneCONTENT_URI,空,Phone_CONTACT_ID +=?,新的String [] {} CONTACT_ID,NULL);                    而(phoneCursor.moveToNext()){                        phoneNumber的= phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER));                    //南的String [] =新的String [] {名};                    // Toast.makeText(getApplicationContext(),南安[0],Toast.LENGTH_LONG).show();                        ch.setText(phoneNumber的);                    // t1.setText(名);                        ch.setChecked(真);                    }                    phoneCursor.close(); 

解决方案

我尝试这个code去取我的联系

  {尝试            串选择=((+ Contacts.DISPLAY_NAME +NOTNULL)AND(                    + Contacts.HAS_PHONE_NUMBER += 1)AND(                    + Contacts.DISPLAY_NAME +=''))!;            光标C = cntx.getContentResolver()查询(Contacts.CONTENT_URI,CONTACTS_SUMMARY_PROJECTION,选择,                    空,Contacts.DISPLAY_NAME +分页中局部ASC);            的for(int i = 0; I< c.getCount();我++)            {// contactWrap.clear();                尝试{                    的ContactID = 0;                    串hasPhone =;                    DISPLAY_NAME =;                    phoneNumber的=;                    c.moveToPosition(ⅰ);                    的ContactID = c.getLong(0);                    DISPLAY_NAME = c.getString(1);                    hasPhone = c.getString(7);                    如果(hasPhone.equalsIgnoreCase(1))                        hasPhone =真;                    其他                        hasPhone =假;                    如果(Boolean.parseBoolean(hasPhone))                    {                        。光标手机= cntx.getContentResolver()查询(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,空,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +=+的ContactID,NULL,NULL);                        而(phones.moveToNext())                        {                            INT indexPhoneType = phones.getColumnIndexOrThrow(Phone.TYPE);                            字符串PHONETYPE = phones.getString(indexPhoneType);                            phoneNumber的= phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));                            串lookupKey = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));                            contactWrap.add(新ContactsWrapper(的ContactID,DISPLAY_NAME,phoneNumber的,lookupKey,假的,COLOR_STRING));                        }// map.put(的ContactID,新的ArrayList< ContactsWrapper>(contactWrap));                        phones.close();                    }                }赶上(例外五){                    e.printStackTrace();                }            }        }        赶上(例外五){            // TODO:处理异常            e.printStackTrace();        }        } 
如何把iphone手机拍摄的照片传给电脑或者其它设备

香港乐施会美国可以从这个光标采取的ContactID或code现在这是我的方法,这将给U触点照片只是通过接触式ID在它

 公众的InputStream openPhoto(长的ContactID){     乌里contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI,使用ContactID);     乌里photoUri = Uri.withAppendedPath(contactUri,Contacts.Photo.CONTENT_DIRECTORY);     光标光标= getContentResolver()查询(photoUri,          新的String [] {} Contacts.Photo.PHOTO,NULL,NULL,NULL);     如果(光标== NULL){         返回null;     }     尝试{         如果(cursor.moveToFirst()){             字节[]数据= cursor.getBlob(0);             如果(数据!= NULL){                 返回新ByteArrayInputStream的(数据);             }         }     } {最后         cursor.close();     }     返回null; } 

希望这将帮助ü好运花花公子

Hello I am new on android development and I am struggling badly with coding...I have to get full contact list of my device in to dynamic growing checkbox name which can be selectable .... It must be selected already and also which will grow dynamically I have tried a lot of things already but dont find any answers...and I have to get the selected contacted from it on button press

public void fetchContacts() {

        String phoneNumber = null;

         LayoutInflater layoutInflater = 
                  (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                final View addView = layoutInflater.inflate(R.layout.contact, null);

        Uri CONTENT_URI = ContactsContract.Contacts.CONTENT_URI;
        String _ID = ContactsContract.Contacts._ID;
        String DISPLAY_NAME = ContactsContract.Contacts.DISPLAY_NAME;
        String HAS_PHONE_NUMBER = ContactsContract.Contacts.HAS_PHONE_NUMBER;

        Uri PhoneCONTENT_URI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
        String Phone_CONTACT_ID = ContactsContract.CommonDataKinds.Phone.CONTACT_ID;
        String NUMBER = ContactsContract.CommonDataKinds.Phone.NUMBER;

        StringBuffer output = new StringBuffer();

        ContentResolver contentResolver = getContentResolver();

        Cursor cursor = contentResolver.query(CONTENT_URI, null,null, null, null);  

        // Loop for every contact in the phone
        if (cursor.getCount() > 0) {

            while (cursor.moveToNext()) {

                String contact_id = cursor.getString(cursor.getColumnIndex( _ID ));
                String name = cursor.getString(cursor.getColumnIndex( DISPLAY_NAME ));

                int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex( HAS_PHONE_NUMBER )));

                if (hasPhoneNumber > 0) {

                    output.append("\n Name:" + name);

                    // Query and loop for every phone number of the contact
                    Cursor phoneCursor = contentResolver.query(PhoneCONTENT_URI, null, Phone_CONTACT_ID + " = ?", new String[] { contact_id }, null);

                    while (phoneCursor.moveToNext()) {
                        phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER));
                    //  String nam[]=new String[]{name};
                    //  Toast.makeText(getApplicationContext(), nam[0],Toast.LENGTH_LONG).show();
                        ch.setText(phoneNumber);
                    //  t1.setText(name);
                        ch.setChecked(true);

                    }

                    phoneCursor.close();

解决方案

i try this code to fetch my contact

try {
            String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("
                    + Contacts.HAS_PHONE_NUMBER + "=1) AND ("
                    + Contacts.DISPLAY_NAME + " != '' ))";

            Cursor c = cntx.getContentResolver().query(Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select,
                    null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");


            for(int i=0;i<c.getCount();i++)
            {
//              contactWrap.clear();
                try {
                    contactId = 0;
                    String hasPhone = "";
                    display_name = "";
                    phoneNumber = "";

                    c.moveToPosition(i);

                    contactId =  c.getLong(0);
                    display_name = c.getString(1);
                    hasPhone = c.getString(7);

                    if (hasPhone.equalsIgnoreCase("1"))
                        hasPhone = "true";
                    else
                        hasPhone = "false" ;

                    if (Boolean.parseBoolean(hasPhone)) 
                    {
                        Cursor phones = cntx.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
                        while (phones.moveToNext()) 
                        {
                            int indexPhoneType = phones.getColumnIndexOrThrow(Phone.TYPE);
                            String phoneType =  phones.getString(indexPhoneType);

                            phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); 

                            String lookupKey = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));


                            contactWrap.add(new ContactsWrapper(contactId, display_name, phoneNumber,lookupKey,false,color_string));
                        }
//                      map.put(contactId, new ArrayList<ContactsWrapper>(contactWrap));
                        phones.close();
                    }
                } catch (Exception e) {

                    e.printStackTrace();
                }  
            }
        }
        catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        }

ohk u can take contactID from this cursor or your code now this is my method which will give u contact photo just pass contact ID in it

public InputStream openPhoto(long contactId) {
     Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
     Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
     Cursor cursor = getContentResolver().query(photoUri,
          new String[] {Contacts.Photo.PHOTO}, null, null, null);
     if (cursor == null) {
         return null;
     }
     try {
         if (cursor.moveToFirst()) {
             byte[] data = cursor.getBlob(0);
             if (data != null) {
                 return new ByteArrayInputStream(data);
             }
         }
     } finally {
         cursor.close();
     }
     return null;
 }

Hope this will help u Best of luck dude