Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中发送vcard/contacts/?vcf var SMS或彩信?_Android_Sms_Mms_Vcf Vcard - Fatal编程技术网

如何在Android中发送vcard/contacts/?vcf var SMS或彩信?

如何在Android中发送vcard/contacts/?vcf var SMS或彩信?,android,sms,mms,vcf-vcard,Android,Sms,Mms,Vcf Vcard,我想修改Android源代码,它可以通过以下方式发送(contacts/vcard/.vcf文件) 彩信或短信,Android默认方式是通过蓝牙。 我找到了很多方法,但都不管用。 我知道vcf格式如下: BEGIN:VCARD VERSION:2.1 N:;lybeen;;; FN:lybeen TEL;CELL; PREF:1-123-234-1234 TEL;CELL:000-111-1111 END:VCARD 我通过短信将此字符串作为普通消息发送。一些安卓手机可以将其识别为联系人,但大

我想修改Android源代码,它可以通过以下方式发送(contacts/vcard/.vcf文件) 彩信或短信,Android默认方式是通过蓝牙。 我找到了很多方法,但都不管用。 我知道vcf格式如下:

BEGIN:VCARD
VERSION:2.1
N:;lybeen;;;
FN:lybeen
TEL;CELL;
PREF:1-123-234-1234
TEL;CELL:000-111-1111
END:VCARD
我通过短信将此字符串作为普通消息发送。一些安卓手机可以将其识别为联系人,但大多数安卓手机无法识别,但我不知道如何通过彩信发送联系人。


您可能可以从SmsManager类发送vcard调用方法sendDataMessage。这意味着您不能将vcard作为普通消息发送,但需要将vcard编码为十六进制。或者你也可以看看这个

虽然我认为我回答这个问题已经晚了,它是否会对OP有所帮助,但它对未来的访客总是有帮助的

要通过彩信发送Vcard,您只需按照系统的意图附加
.vcf
文件

            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.setType("text/x-vcard");
            sendIntent.putExtra(Intent.EXTRA_STREAM,
                    Uri.fromFile(outputFile));
            startActivity(sendIntent);

这可能对你有帮助。根据你的需要试试这个-

package com.vcard;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;

import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.View;

public class VCardActivity extends Activity 
{
    Cursor cursor;
    ArrayList<String> vCard ;
    String vfile;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        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 Conatact
         * 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() {
        // TODO Auto-generated method stub
        vCard = new ArrayList<String>();
        cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
        if(cursor!=null&&cursor.getCount()>0)
        {
            cursor.moveToFirst();
            for(int i =0;i<cursor.getCount();i++)
            {

                get(cursor);
                Log.d("TAG", "Contact "+(i+1)+"VcF String is"+vCard.get(i));
                cursor.moveToNext();
            }

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

    }

    public void get(Cursor cursor)
    {
        //cursor.moveToFirst();
        String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
        AssetFileDescriptor fd;
        try {
            fd = this.getContentResolver().openAssetFileDescriptor(uri, "r");

            // Your Complex Code and you used function without loop so how can you get all Contacts Vcard.??
           /* FileInputStream fis = fd.createInputStream();
            byte[] buf = new byte[(int) fd.getDeclaredLength()];
            fis.read(buf);
            String VCard = new String(buf);
            String path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile;
            FileOutputStream out = new FileOutputStream(path);
            out.write(VCard.toString().getBytes());
            Log.d("Vcard",  VCard);*/

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

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

        } catch (Exception e1) 
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}
package com.vcard;
导入java.io.File;
导入java.io.FileInputStream;
导入java.io.FileOutputStream;
导入java.util.ArrayList;
导入android.app.Activity;
导入android.content.res.AssetFileDescriptor;
导入android.database.Cursor;
导入android.net.Uri;
导入android.os.Bundle;
导入android.os.Environment;
导入android.provider.contacts合同;
导入android.util.Log;
导入android.view.view;
公共类VCardActivity扩展了活动
{
光标;
ArrayList vCard;
字符串vfile;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vfile=“Contacts”+“\u”+System.currentTimeMillis()+”.vcf”;
/**此函数用于Vcard,这里我使用一个数组列表,其中存储每个Conatact的每个Vcard字符串
*这里我取一个游标,这个游标不是空的,它的计数>0,然后我重复一个循环到游标。getcount()表示最多有多少个电话联系人。
*在每个循环中,我可以生成vcard字符串并存储在数组列表中,我将其声明为全局数组。
*在每个循环中,我移动光标,然后在logcat中打印日志。
* */
getVcardString();
}
私有void getVcardString(){
//TODO自动生成的方法存根
vCard=新的ArrayList();
cursor=getContentResolver().query(ContactsContract.CommonDataTypes.Phone.CONTENT\u URI,null,null,null);
if(cursor!=null&&cursor.getCount()>0)
{
cursor.moveToFirst();

对于(int i=0;我觉得这是一个更一般的问题,在这里可以找到更多,无论如何,这似乎不是一个特定于编程的问题。我想通过在android源代码中编程来实现,我发现它不容易实现realize@lybeen你们找到解决方案了吗?嘿,朋友们,我正在开发一个聊天应用程序,所以我想在聊天中发送联系人,比如whats应用程序,所以请帮助我这就是如何获得解决方案。谢谢