0

Я хочу отправить файл vcf для связи с помощью Bluetooth и электронной почты. Я попытался, но я продолжаю получать ошибки. Пожалуйста помоги. СпасибоОтправка файла контакта .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:"));  

} 

Пожалуйста, помогите! Благодарю.

+0

Почему вы "intent.setType (" image/png ");'? –

+0

Я не знаю, что использовать setType() –

ответ

1

Для Bluetooth вы можете установить тип, как 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[] = {"[email protected]"}; 
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...")); 

Просто побочное замечание: The.vcf файл должен быть в вашей SD карты