我想使用蓝牙和电子邮件发送联系人VCF文件。我试过了,但我总是出错。请帮助。由于
这是我的sendByBluetooth方法。
public void sendByBluetooth(){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(storage_path) );
startActivity(intent);
}
这是我的emailContact方法
public void emailContact() {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Add attributes to the intent
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.putExtra(Intent.EXTRA_SUBJECT,"subject line");
sendIntent.putExtra(Intent.EXTRA_TEXT,"Body of email");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(storage_path)));
sendIntent.setType("vnd.android.cursor.dir/email");
startActivity(Intent.createChooser(sendIntent,"Email:"));
}
请帮忙!谢谢。
对于蓝牙,您可以将类型设置为intent.setType("text/x-vcard");
public void sendByBluetooth(){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/x-vcard");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(storage_path) );
startActivity(intent);
}
对于电子邮件,可以使用
String filelocation="/mnt/sdcard/contacts.vcf";
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"asd@gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, filelocation);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
只是一个边注:。vcf文件应该在SD卡中