本文介绍了在API级别8制作名片时DONOT插入图片来源$ C ​​$ C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这code做了Vcard,现在我想在我的名片不插入图像code,其他都将在电子名片添加,我该怎么办呢....我使用这种

 字符串电子名片=;         。光标手机= getContentResolver()查询(android.provider.ContactsContract.Contacts.CONTENT_URI,NULL,NULL,NULL,NULL);
         phones.moveToFirst();
         pDialog.setMax(phones.getCount());
           的for(int i = 0; I< phones.getCount();我++)
           {              串lookupKey = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
              URI URI = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI,lookupKey);              AssetFileDescriptor的fd;
             尝试
             {
                 FD = getContentResolver()openAssetFileDescriptor(URI,R)。
                 FIS的FileInputStream = fd.createInputStream();
                 字节[] buf中=新的字节[(INT)fd.getDeclaredLength()];
                 fis.read(BUF);
                 电子名片+ =新的String(BUF);
                 y字符串=将String.valueOf(ⅰ);
                 publishProgress(Y);
                 phones.moveToNext();
                 Log.d(电子名片,电子名片);
             }
             赶上(例外E1)
             {
                  // TODO自动生成catch块
                  e1.printStackTrace();
             }         }        尝试{
            FileOutputStream中mFileOutputStream =新的FileOutputStream(文件,FALSE);
              mFileOutputStream.write(VCard.toString()的getBytes());
              mFileOutputStream.close();
        }赶上(IOException异常五){
            // TODO自动生成catch块
            e.printStackTrace();
        }


解决方案

 字符串lookupKey = phones.getString(电话
    .getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
乌里vcardUri = ContactsContract.Contacts.CONTENT_VCARD_URI
    。建立在()
    .appendQueryParameter(nophoto,将S​​tring.valueOf(真))
    。建立();
URI URI = Uri.withAppendedPath(vcardUri,lookupKey);

我必须再次进行修改,使用循环

I am making Vcard using this code , now I want In my vcard don't insert code of image , all other things will added in vcard , how I do it .... I'm using this

         String VCard = "";

         Cursor phones = getContentResolver().query(android.provider.ContactsContract.Contacts.CONTENT_URI , null,null, null, null);
         phones.moveToFirst();
         pDialog.setMax(phones.getCount());
           for(int i =0;i<phones.getCount();i++)
           {

              String lookupKey =  phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
              Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);

              AssetFileDescriptor fd;
             try 
             {
                 fd = getContentResolver().openAssetFileDescriptor(uri, "r");
                 FileInputStream fis = fd.createInputStream();
                 byte[] buf = new byte[(int) fd.getDeclaredLength()];
                 fis.read(buf);
                 VCard += new String(buf);
                 String y =String.valueOf(i);
                 publishProgress(y);
                 phones.moveToNext();                           
                 Log.d("Vcard",  VCard);
             } 
             catch (Exception e1) 
             {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
             }

         }

        try {
            FileOutputStream mFileOutputStream = new FileOutputStream(file, false);
              mFileOutputStream.write(VCard.toString().getBytes());
              mFileOutputStream.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
解决方案
    String lookupKey = phones.getString(phones
    .getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri vcardUri = ContactsContract.Contacts.CONTENT_VCARD_URI
    .buildUpon()
    .appendQueryParameter("nophoto", String.valueOf(true))
    .build();
Uri uri = Uri.withAppendedPath(vcardUri, lookupKey);

I have modify it again,use in for loop

这篇关于在API级别8制作名片时DONOT插入图片来源$ C ​​$ C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 10:59