0

i want to send a contact vcf file using the bluetooth and email. I have tried but i keep getting errors. Please help. Thanks

This is my sendByBluetooth method.

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);
}

This is my emailContact method.

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:"));       

}

Please Help! Thanks.

2
  • Why do you intent.setType("image/png"); ? Sep 22, 2015 at 20:18
  • I do not know what setType() to use Sep 23, 2015 at 12:12

1 Answer 1

2

For bluetooth you can set the type as 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);
}

and for emails you could use

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..."));

Just a side note: The.vcf file should be in in your SD card

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.