0

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.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

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>
philm
  • 797
  • 1
  • 8
  • 29
  • if you feel a post was closed or marked duplicate in error, there is a process to re-open it. Posting a new question is not the correct process. – Jason Mar 26 '21 at 19:54
  • I have voted to re-open the question but I really need an answer on this ASAP – philm Mar 26 '21 at 20:01
  • https://meta.stackoverflow.com/questions/326569/under-what-circumstances-may-i-add-urgent-or-other-similar-phrases-to-my-quest – Jason Mar 26 '21 at 20:03
  • Why do you still have this line `Android.Net.Uri uri = Android.Net.Uri.FromFile(someFile);` and where is `contentURI` being used. – Nongthonbam Tonthoi Mar 27 '21 at 01:17
  • This line has been removed. After reviewing the source, this line is not used at all – philm Apr 01 '21 at 16:33

0 Answers0