的Andr​​oid如何发送多个触点被安装在单独的.vcf文件并传送到邮件? [英] Android How to send multiple contacts are attached in single .vcf file and send to mail?

查看:104
本文介绍了的Andr​​oid如何发送多个触点被安装在单独的.vcf文件并传送到邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在接触我的应用程序数量连接到单独的.vcf文件和文件发送至邮箱,尝试这个日志猫的所有联系人数据显示,但无法发送连接到单独的.vcf文件中的所有数据?

任何一个有关于这个帮助我的想法,请..

这是我的code

 公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    电子名片=新的ArrayList<字符串>();

    Log.i(TAG一,vfile+ vfile);
    vfile =联系人+_+ System.currentTimeMillis的()+的.vcf;

    / **
     *此功能vCard和这里我需要一个数组列表中,我
     *商店每维卡字符串的所有联系人在这里,我需要一个光标和
     *该游标不为空,并计数大于0比我重复一环达
     * cursor.getcount()是指最多的手机通讯录号码。并在每
     *循环我可以让电子名片串并存储在其中我声明数组列表
     *作为全球。并在每圈I移动光标旁边和打印日志
     * logcat的。
     * * /
    getVcardString();
}

私人无效getVcardString(){

    光标= getContentResolver()查询(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,NULL,NULL,NULL,NULL);
    Log.i(TAG二,光标+光标);
    如果(光标=空&安培;!&安培; cursor.getCount()大于0){
        cursor.moveToFirst();
        Log.i(触点数,cursorCount+ cursor.getCount());

        的for(int i = 0; I< cursor.getCount();我++){
            得到(光标);
            Log.i(TAG发送联系人,联系方式+(I + 1)+VCF字符串为+ vCard.get(一));
            cursor.moveToNext();
        }

        StringBuffer的S =新的StringBuffer();
        s.append(vCard.toString());
        字符串= s.toString();
        文件=新的文件(字符串);

    // Log.i(S,+ S);
    // Log.i(字符串,+字符串);
        Log.i(文件,+文件);

    } 其他 {
        Log.i(TAG,在你的手机号联系人);
    }
}

公共无效的get(光标指针){

    串lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
    Log.i(lookupKey,+ lookupKey);
    开放的我们的uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI,lookupKey);

    尝试 {
        AssetFileDescriptor FD = this.getContentResolver()openAssetFileDescriptor(URI,R)。

        的FileInputStream FIS = fd.createInputStream();
        byte []的BUF =新的字节[(INT)fd.getDeclaredLength()];
        fis.read(BUF);
        字符串vcardstring =新的String(BUF);

        字符串storage_path = Environment.getExternalStorageDirectory()的toString()+文件分割符+ vfile。
        FileOutputStream中mFileOutputStream =新的FileOutputStream(storage_path,真正的);
        mFileOutputStream.write(vcardstring.toString()的GetBytes());

        vCard.add(storage_path);

    }赶上(例外E1){
        e1.printStackTrace();
    }
}

私人无效数据(){

    文件fil​​elocation =文件;
    意图sharingIntent =新的意图(Intent.ACTION_SEND);
    sharingIntent.setType(vnd.android.cursor.dir /电子邮件);
    sharingIntent.setType(应用程序/ x-名片);
    sharingIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(文件://+ filelocation));
    startActivity(Intent.createChooser(sharingIntent,发送电子邮件));
}
}
 

解决方案

终于我的问题是使用这样解决了。

 公共无效的onCreate(包savedInstanceState){
     super.onCreate(savedInstanceState);
     的setContentView(R.layout.main);

     mContext =这一点;

     按钮=(按钮)findViewById(R.id.send);
     button.setOnClickListener(新OnClickListener(){
        公共无效的onClick(视图v){
            数据();
        }
    });

    / **
     *此功能vCard和这里我需要一个数组列表中,我
     *商店每维卡字符串的所有联系人在这里,我需要一个光标和
     *该游标不为空,并计数大于0比我重复一环达
     * cursor.getcount()是指最多的手机通讯录号码。并在每
     *循环我可以让电子名片串并存储在其中我声明数组列表
     *作为全球。并在每圈I移动光标旁边和打印日志
     * logcat的。
     * * /
    getVcardString();
}

 公共静态无效getVcardString(){

    字符串路径= NULL;
    字符串vfile = NULL;

     vfile =Contacts.vcf;
    光标手机= mContext.getContentResolver()查询(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,空,
                    NULL,NULL,NULL);

    phones.moveToFirst();
    Log.i(芯数,cursorCount+ phones.getCount());
    的for(int i = 0; I< phones.getCount();我++){

         串lookupKey = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
         Log.i(lookupKey,+ lookupKey);
         开放的我们的uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI,lookupKey);
         AssetFileDescriptor的fd;

         尝试  {
             FD = mContext.getContentResolver()openAssetFileDescriptor(URI,R)。
             的FileInputStream FIS = fd.createInputStream();
             byte []的BUF =新的字节[(INT)fd.getDeclaredLength()];
             fis.read(BUF);
             字符串电子名片=新的String(BUF);

             。PATH = Environment.getExternalStorageDirectory()的toString()+文件分割符+ vfile;
             FileOutputStream中mFileOutputStream =新的FileOutputStream(路径,真实);
             mFileOutputStream.write(VCard.toString()的GetBytes());

             phones.moveToNext();

             filevcf =新的文件(路径);
             Log.i(文件,文件+ filevcf);

         }赶上(例外E1){
             e1.printStackTrace();
         }
    }
    Log.i(TAG,在你的手机号联系人);
}

保护无效数据(){
    文件fil​​elocation = filevcf;
    意图sharingIntent =新的意图(Intent.ACTION_SEND);
    sharingIntent.setType(vnd.android.cursor.dir /电子邮件);
    sharingIntent.setType(应用程序/ x-名片);
    sharingIntent.putExtra(Intent.EXTRA_EMAILmail@gmail.com);
    sharingIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(文件://+ filelocation.getAbsolutePath()));
    startActivity(Intent.createChooser(sharingIntent,发送电子邮件));
 }
 

In my App number of contacts are attached to single .vcf file and that file sent to mail, try to this one all contacts data display in log cat, but unable to send all data attached to single .vcf file?

Any one have idea regarding this help me please..

here is my code

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);  

    vCard = new ArrayList<String>();                 

    Log.i("TAG one", "vfile" +vfile);
    vfile = "Contacts" + "_" + System.currentTimeMillis() + ".vcf";  

    /**
     * This Function For Vcard And here i take one Array List in Which i
     * store every Vcard String of Every Contact Here i take one Cursor and
     * this cursor is not null and its count>0 than i repeat one loop up to
     * cursor.getcount() means Up to number of phone contacts. And in Every
     * Loop i can make vcard string and store in Array list which i declared
     * as a Global. And in Every Loop i move cursor next and print log in
     * logcat.
     * */
    getVcardString();           
}       

private void getVcardString() { 

    cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
    Log.i("TAG two", "cursor" +cursor);
    if (cursor != null && cursor.getCount() > 0) {
        cursor.moveToFirst();
        Log.i("Number of contacts", "cursorCount" +cursor.getCount());          

        for (int i = 0; i < cursor.getCount(); i++) {                       
            get(cursor);                    
            Log.i("TAG send contacts",  "Contact " + (i + 1) + "VcF String is" +  vCard.get(i));                     
            cursor.moveToNext();                                        
        }           

        StringBuffer s = new StringBuffer();
        s.append( vCard.toString());                
        string = s.toString();                           
        file = new File(string);        

    //  Log.i("s", ""+s);   
    //  Log.i("string", ""+string); 
        Log.i("file", ""+file);             

    } else {
        Log.i("TAG", "No Contacts in Your Phone");
    }        
}       

public void get(Cursor cursor) {

    String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
    Log.i("lookupKey", ""+lookupKey);
    Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);     

    try {
        AssetFileDescriptor fd = this.getContentResolver().openAssetFileDescriptor(uri, "r");          

        FileInputStream fis = fd.createInputStream();
        byte[] buf = new byte[(int) fd.getDeclaredLength()];
        fis.read(buf);
        String vcardstring= new String(buf);          

        String storage_path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile;
        FileOutputStream mFileOutputStream = new FileOutputStream(storage_path, true);
        mFileOutputStream.write(vcardstring.toString().getBytes());

        vCard.add(storage_path);            

    } catch (Exception e1)  {            
        e1.printStackTrace();
    }
}       

private void data() {       

    File filelocation = file;     
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("vnd.android.cursor.dir/email");      
    sharingIntent.setType("application/x-vcard");             
    sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+filelocation));
    startActivity(Intent.createChooser(sharingIntent, "Send email"));            
}
}    

解决方案

finally my issue is solved using like this

     public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);     

     mContext = this; 

     button = (Button) findViewById(R.id.send);          
     button.setOnClickListener(new OnClickListener() {          
        public void onClick(View v) {        
            data();
        }
    });                      

    /**
     * This Function For Vcard And here i take one Array List in Which i
     * store every Vcard String of Every Contact Here i take one Cursor and
     * this cursor is not null and its count>0 than i repeat one loop up to
     * cursor.getcount() means Up to number of phone contacts. And in Every
     * Loop i can make vcard string and store in Array list which i declared
     * as a Global. And in Every Loop i move cursor next and print log in
     * logcat.
     * */
    getVcardString();           
}       

 public static void getVcardString() {   

    String path = null;     
    String vfile = null;

     vfile = "Contacts.vcf";           
    Cursor phones = mContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                    null, null, null);

    phones.moveToFirst();
    Log.i("Number of contacts", "cursorCount" +phones.getCount());  
    for(int i =0;i<phones.getCount();i++)   {       

         String lookupKey = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
         Log.i("lookupKey", " " +lookupKey);
         Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
         AssetFileDescriptor fd;

         try  {
             fd = mContext.getContentResolver().openAssetFileDescriptor(uri, "r");
             FileInputStream fis = fd.createInputStream();
             byte[] buf = new byte[(int) fd.getDeclaredLength()];
             fis.read(buf);
             String VCard = new String(buf);          

             path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile;
             FileOutputStream mFileOutputStream = new FileOutputStream(path, true);
             mFileOutputStream.write(VCard.toString().getBytes());    

             phones.moveToNext();               

             filevcf = new File(path);
             Log.i("file", "file" +filevcf);

         }catch(Exception e1) {
             e1.printStackTrace();  
         }
    }       
    Log.i("TAG", "No Contacts in Your Phone");          
}

protected void data() {             
    File filelocation = filevcf ;     
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("vnd.android.cursor.dir/email");      
    sharingIntent.setType("application/x-vcard");       
    sharingIntent.putExtra(Intent.EXTRA_EMAIL, "mail@gmail.com" );        
    sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+filelocation.getAbsolutePath()));
    startActivity(Intent.createChooser(sharingIntent, "Send email"));            
 }  

这篇关于的Andr​​oid如何发送多个触点被安装在单独的.vcf文件并传送到邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆