I'm trying to start an Intent from a Unity app that will launch the text messaging app with an attachment.
I have been able to open the text messaging app but the attachment does not load properly, throwing the following exception:
'Could not determine type of file:///storage/emulated/0/Android/data/com.torpedoesaway.memematch/files/Gifit2MemeFiles/gifit2meme-2019-09-7-09-39-54.gif java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0x80000000'
Note that I have also tried loading other images, such as pngs and jpgs, all throwing the same error.
This is my code:
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:" + recipient));
intent.putExtra("sms_body", message);
intent.putExtra(Intent.EXTRA_STREAM, attachment);
if (intent.resolveActivity(activity.getPackageManager()) != null) {
activity.startActivity(intent);
}
I tried playing around with the intent action as well as the setData
/setType
calls and in one instance I am able to open the chooser, select the messaging app and then the attachment is loaded properly. However, I want to open the text messaging app directly with the attachment working.
Thanks in advance for the help!
Edit:
How I'm making the call from Unity:
AndroidJavaClass Uri = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject uri = Uri.CallStatic<AndroidJavaObject>("parse", path);
unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
pluginClass = new AndroidJavaObject("com.torpedosaway.giftomessage.Gif2Message");
pluginClass.Call(
"ComposeMmsMessage",
"53876045",
"message",
uri,
unityClass.GetStatic<AndroidJavaObject>("currentActivity"));
Just before you call startActivity(intent);
Add these lines:
StrictMode.VmPolicy.Builder builder = StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
Then call
startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With