Created
May 14, 2016 15:22
-
-
Save technoplato/f269f43231fa2ab25cadd1a41fcfe184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void sendMmsToContact(C destinationContact) { | |
File vcfFile = null; | |
try { | |
vcfFile = new File(this.getExternalCacheDir(), destinationContact.getName().replaceAll(" ", "") + ".vcf"); | |
FileWriter fw = new FileWriter(vcfFile); | |
fw.write("BEGIN:VCARD\r\n"); | |
fw.write("VERSION:3.0\r\n"); | |
fw.write("N:" + "Lustig" + ";" + "Michael" + "\r\n"); | |
fw.write("FN:" + "Michael Lustig" + "\r\n"); | |
// fw.write("ORG:" + "Google" + "\r\n"); | |
fw.write("TEL;TYPE=cell,VOICE:" + "6189808247" + "\r\n"); | |
// fw.write("TEL;TYPE=HOME,VOICE:" + p.getHomePhone() + "\r\n"); | |
// fw.write("ADR;TYPE=WORK:;;" + p.getStreet() + ";" + p.getCity() + ";" + p.getState() + ";" + p.getPostcode() + ";" + p.getCountry() + "\r\n"); | |
// fw.write("EMAIL;TYPE=PREF,INTERNET:" + "mlustig@google.com" + "\r\n"); | |
fw.write("END:VCARD\r\n"); | |
fw.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
// TODO: Cleanup generated vcard file from internal storage | |
Log.d("Lustig", "Uri: " + Uri.parse(vcfFile.toURI().toString())); | |
try { | |
Intent sendIntent = new Intent(Intent.ACTION_SEND); | |
sendIntent.setType("text/x-vcard"); | |
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
sendIntent.putExtra(Intent.EXTRA_STREAM, | |
Uri.parse(vcfFile.toURL().toString())); | |
// sendIntent.setType("vnd.android-dir/mms-sms"); | |
// sendIntent.putExtra("address", "12125551212"); | |
startActivity(sendIntent); | |
// Intent myIntent = new Intent(Intent.ACTION_SEND); | |
//// File file = new File(aFile.getAbsolutePath()); | |
// String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(vcfFile).toString()); | |
// String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); | |
// myIntent.setDataAndType(Uri.fromFile(vcfFile), mimetype); | |
// myIntent.putExtra("address", destinationContact.getPhone()); | |
//// myIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(vcfFile.toURI().toString())); | |
// myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
// startActivity(myIntent); | |
} catch (Exception e) { | |
// TODO: handle exception | |
String data = e.getMessage(); | |
Log.d(TAG, "sendMmsToContact: data: " + data); | |
} | |
// myIntent.putExtra("address", destinationContact.getPhone()); | |
// myIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(vcfFile.toURI().toString())); | |
// myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
// sendIntent.setAction(android.content.Intent.ACTION_VIEW); | |
// sendIntent.setDataAndType(Uri.fromFile(vcfFile), "text/x-vcard"); | |
// startActivity(sendIntent); | |
// Intent sendIntent = new Intent(Intent.ACTION_SEND); | |
// sendIntent.setType("text/x-vcard"); | |
// sendIntent.putExtra(Intent.EXTRA_STREAM, | |
// Uri.parse(outputFile.toURL().toString())); | |
// startActivity(sendIntent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment