I am working on an Android application that is already successfully sharing a generated PDF file via Bluetooth using the following method:
public static void sharePdfFile(Context ctx, String pathAndFile) {
try {
Intent share = new Intent(Intent.ACTION_SEND);
share.setPackage("com.android.bluetooth");
share.setType("application/pdf");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(pathAndFile));
share.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(share);
} catch (Exception e) {
ExceptionDAO.Log(CATEGORY.SHARE_INTENT, e, ctx, e.getMessage(), true);
}
}
I have been asked to include a second file (CSV format) in this share intent so that both files are sent together. I immediately found this question, which addresses sending multiple files via Bluetooth, but only using files of the same MIME type ("video/*" in that example.)
I have found plenty of examples of wildcard MIME subtypes ("video/*", "text/*", etc.) but at this point I been unable to find any examples of an Intent with more than one specific MIME type set (example: "application/pdf" and "text/comma-separated-values"). So, I created a test method using "*/*" as the MIME type hoping that would do the trick. Unfortunately, my test method is not even getting far enough to activate the Bluetooth share popup to select a nearby device.
I am not sure what I am doing wrong or have left out. I cannot seem to trap any errors while debugging so I assume I'm still missing something. I do know the PDF and CSV files and their respective URI's are OK because both files transmit fine through the original method (I changed the MIME type and URI on the existing method to test the new CSV file.)
Here is my test method:
public static void shareTwoFilesTest(Context ctx, String pathAndFile, String pathAndFile2) {
try {
Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
share.setPackage("com.android.bluetooth");
share.setType("*/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(pathAndFile));
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(pathAndFile2));
share.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(share);
} catch (Exception e) {
ExceptionDAO.Log(CATEGORY.SHARE_INTENT, e, ctx, e.getMessage(), true);
}
}