private void sendPhotoByEmail(Uri photoUri, String[] emailTo) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.setType("message/rfc822");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, emailTo);
String intro;
if (mData != null) {
intro = mData.optString(DecisionTree.EMAIL_BODY, getString(R.string.share_photo_email_body_format));
} else {
intro = getString(R.string.share_photo_email_body_format);
}
intro = String.format("%s\n\n%s", intro, getString(R.string.share_photo_email_body_footer,
ApplicationContext.getFormattedVersionInfo(this)));
String locationText = intro + ApplicationContext.getUserLocationBody();
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.share_photo_subject));
intent.putExtra(android.content.Intent.EXTRA_TEXT, locationText);
intent.putExtra(Intent.EXTRA_STREAM, photoUri);
startActivity(intent);
}
private void sendPhotoByText(Uri photoUri, String phoneTo) {
Toast.makeText(this, "In sendPhotoByText", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.setType("image/*");
intent.setData(Uri.parse("smsto:" + phoneTo));
String intro;
if (mData != null) {
intro = mData.optString(DecisionTree.EMAIL_BODY, getString(R.string.share_photo_email_body_format));
} else {
intro = getString(R.string.share_photo_email_body_format);
}
intro = String.format("%s\n\n%s", intro, getString(R.string.share_photo_email_body_footer,
ApplicationContext.getFormattedVersionInfo(this)));
String locationText = intro + ApplicationContext.getUserLocationBody();
intent.putExtra("sms_body", locationText);
intent.putExtra(Intent.EXTRA_STREAM, photoUri);
startActivity(intent);
}
In my app, the user chooses a photo from the Gallery. It is saved and the uri is passed to one of the two methods above. The sendPhotoByEmail method formats an email with the photo in it. The sendPhotoByText method formats a text message. The photo does not appear in it, and I see the error message "Unable to attach. File not supported". I have tested with the same photo (same uri) in each function. The uri is "content://media/external/images/media/1017". I have also run Messenger separately and was able to attach the same photo successfully.
I have set the SMS and Storage permissions in the app on my device, and these are the permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.SEND_SMS />
Any insights would be greatly appreciated.
Believe it or not, I replaced
intent.setData(Uri.parse("smsto:" + phoneTo));
with
intent.putExtra("address", phoneTo);
and the photo appeared in the formatted text message. However, the screen that shows apps to choose from (which previously showed only text messaging apps) now shows other apps as well. I would like it to show only text messaging apps.