微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

需要帮助调试异常错误 - 无法获取提供程序缺少 android.support.FILE_PROVIDER_PATHS

如何解决需要帮助调试异常错误 - 无法获取提供程序缺少 android.support.FILE_PROVIDER_PATHS

我收到异常错误:'Unable to get provider androidx.core.content.FileProvider: java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS Meta-data

这是我的一些代码

public void SendMMSMessage()
        {
            Android.Telephony.SmsManager smsMessage = Android.Telephony.SmsManager.Default;
            IList<string> divideContents = smsMessage.DivideMessage("I auto sent this message to you! No typing here!!!!!");
            string filePath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures) + "/TestPic.jpg";
                
                

            byte[] sendPDUData = GetMMSPDUData("11111111111",filePath,"hey this image was sent from my phone using code! No typing here");

            if (sendPDUData != null)
            {
                SendMMSData(sendPDUData);
            }
        }

        public byte[] GetMMSPDUData(string DestinationNumber,string AudioFilePath,string smsMessage)
        {
            byte[] pduData = null;
            try
            {
                SendReq sendReq = new SendReq();

                sendReq.AddTo(new EncodedStringValue(DestinationNumber));

                Pdubody pdubody = new Pdubody();

                // Add text message data to message
                PduPart txtPart = new PduPart();
                txtPart.SetData(Encoding.ASCII.GetBytes(smsMessage));
                txtPart.SetContentType(new EncodedStringValue("text/plan").GetTextString());
                txtPart.SetName(new EncodedStringValue("Message").GetTextString());
                pdubody.AddPart(txtPart);

                // Add image data 
                // Todo: Later,this will be audio file. But image file for testing
                PduPart imgPart = new PduPart();
                byte[] sampleImageData = System.IO.File.ReadAllBytes(AudioFilePath);

                imgPart.SetData(sampleImageData);
                imgPart.SetContentType(new EncodedStringValue("image/jpg").GetTextString());
                imgPart.SetFilename(new EncodedStringValue(System.IO.Path.GetFileName(AudioFilePath)).GetTextString());
                pdubody.AddPart(imgPart);

                // Now create body of MMS
                sendReq.Body = pdubody;
                // Finally,generate the byte array to send to the MMS provider
                PduComposer composer = new PduComposer(sendReq);
                pduData = composer.Make();
            }
            catch(Exception ex)
            {
                // Todo: Do something here
            }
            return pduData;

        }

        public bool SendMMSData(byte[] PDUData)
        {
            Context CTX = Android.App.Application.Context;
            Android.Telephony.SmsManager sm = Android.Telephony.SmsManager.Default;
            Random rnd = new Random();

            try
            {
                string cacheFilePath = System.IO.Path.Combine(CTX.CacheDir.AbsolutePath,"send." + "sendMe" + ".dat");
                System.IO.File.WriteallBytes(cacheFilePath,PDUData);
                Java.IO.File testFile = new Java.IO.File(cacheFilePath);
                
                string authString = CTX.PackageName + ".fileprovider";
                if (System.IO.File.Exists(cacheFilePath))
                {
                      Android.Net.Uri contentURI = AndroidX.Core.Content.FileProvider.GetUriForFile(CTX,CTX.PackageName + ".fileprovider",testFile);
                //    Android.Net.Uri contentURI = Android.Net.Uri.FromFile(testFile).Au

                   /*     Android.Net.Uri contentURI = (new Android.Net.Uri.Builder())
                       .Authority(authString)
                       .Path(cacheFilePath)
                       .Scheme(ContentResolver.SchemeContent)
                       .Build();
                       */

                    /*
                     * = (new Android.Net.Uri.Builder())
                       .Authority(ctx.PackageName + ".fileprovider")
                       .Path(cacheFilePath)
                       .Scheme(ContentResolver.SchemeContent)
                       .Build();
                       */

                    PendingIntent pendingIntent = PendingIntent.Getbroadcast(CTX,new Intent(CTX.PackageName + ".WAP_PUSH_DELIVER"),0);

                    sm.SendMultimediaMessage(CTX,contentURI,null,null);
                }
            }
            catch(Exception ex)
            {
                String exString = ex.ToString();
                return false;
            }
            return true;
        }

此外,这是我的清单文件

<?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="auto">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
    <application android:label="janinesafety2.Android">
        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <Meta-data
                android:name="android.suport.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_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" />
</manifest>

和我的 Provider_path

<?xml version="1.0" encoding="utf-8" ?>
<paths>
  <external-path
    name="external_file"
    path="./"
  />
</paths>

我已将这些用作资源来帮助我进行调试:

androidx FILE_PROVIDER_PATHS Unable to get provider androidx.core.content.FileProvider: java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data?

不幸的是,我的预期仍然存在问题。据我所知,我正在做每个人都在说的事情。

有没有人可以看一下我的代码?也许我错过了什么。

谢谢。

解决方法

你可以参考下面的代码。

1.将以下内容添加到您的 AndroidManifest.xml 标签内。 YOUR_APP_PACKAGE_NAME 必须设置为您的应用程序包名称。

 <application>
  <provider android:name="android.support.v4.content.FileProvider" 
      android:authorities="YOUR_APP_PACKAGE_NAME.fileprovider" 
      android:exported="false" 
      android:grantUriPermissions="true">
 <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
</provider>
</application>

2.将一个名为 xml 的新文件夹添加到您的 Resources 文件夹中,并添加一个名为 file_paths.xml 的新 XML 文件。添加以下代码:

<?xml version="1.0" encoding="utf-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="." />
<external-path name="external" path="." />
<external-files-path name="external_files" path="." />
<cache-path name="cache" path="." />
<external-cache-path name="external_cache" path="." />
<files-path name="files" path="." />
</paths>

我添加了所有标签。你可以从下面的链接获得。 FileProvider - IllegalArgumentException: Failed to find configured root

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。