I have a simplier question. I am now trying to send MMS through the use of intents. I have used these posts to create my function and setup my code:
Android android.os.FileUriExposedException Error in Android N
Now, my issue is that even though I am setting up everything correctly, I am still getting the error in the title. Would someone take a look to see where things are wrong?
Note: Now before any closes this post, I already looked at this site here: exposed beyond app through ClipData.Item.getUri And I have what they implemented and guess what, I still get the error! So do NOT close this post because I am still getting issues which means, the answer in that post is not sufficient. And that one is in java and not Xamarin!
Code:
public void SendMMSMessage()
{
string filePath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures) + "/TestPic.jpg";
Context CTX = Android.App.Application.Context;
Intent sendIntent = new Intent(Intent.ActionSend);
sendIntent.SetClassName("com.android.mms", "comm.andrdoid.ui.ComposeMessafeActivity");
sendIntent.PutExtra("address", "1111111");
sendIntent.PutExtra("sms_body", "This is a test");
Java.IO.File someFile = new Java.IO.File(filePath);
sendIntent.AddFlags(ActivityFlags.GrantReadUriPermission | ActivityFlags.GrantWriteUriPermission);
Android.Net.Uri uri = Android.Net.Uri.FromFile(someFile);
Android.Net.Uri contentURI = AndroidX.Core.Content.FileProvider.GetUriForFile(CTX, CTX.PackageName + ".provider", someFile);
sendIntent.PutExtra(Intent.ExtraStream, uri);
sendIntent.SetType("jpg/*");
Android.App.Application.Context.StartActivity(sendIntent);
/* byte[] sendPDUData = GetMMSPDUData( Recipient, filePath, MessageBody);
if (sendPDUData != null)
{
SendMMSData(sendPDUData);
}*/
}
File_Paths.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="."/>
</paths>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.janineSafety2" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<application android:label="janinesafety2.Android">
<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
</provider>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
</manifest>