IllegalArgument异常:找不到具有权限的提供者的元数据

显示的错误:           java.lang.IllegalArgumentException:无法找到具有授权者的元数据               $ {applicationId} .fileprovider         在androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:606)         在androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:579)         在androidx.core.content.FileProvider.getUriForFile(FileProvider.java:417)         在com.qhsetech.pdf.MainActivity $ 1.onClick(MainActivity.java:245)         在android.view.View.performClick(View.java:6597)         在android.view.View.performClickInternal(View.java:6574)         在android.view.View.access $ 3100(View.java:778)         在android.view.View $ PerformClick.run(View.java:25885)         在android.os.Handler.handleCallback(Handler.java:873)         在android.os.Handler.dispatchMessage(Handler.java:99)         在android.os.Looper.loop(Looper.java:193)         在android.app.ActivityThread.main(ActivityThread.java:6669)         在java.lang.reflect.Method.invoke(本机方法)         在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:493)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

表现:

    <supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"
           />
    </provider>
  </application>
  </manifest>

PROVIDER_PATHS.XML:

<paths xmlns:android="http://schemas.android.com/apk/res/android">

<files-path
    name="data"
    path="data.csv"/>
 </paths>

维护性:JAVA:

   buttonAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
               try {
                if (et_email.getText().toString().length() == 0 || et_email.getText().toString().length() == 1)
                    Toast.makeText(MainActivity.this, "Please enter email id", Toast.LENGTH_LONG).show();
                else if (et_shipname.getText().toString().length() == 0 || et_shipname.getText().toString().length() == 1)
                    Toast.makeText(MainActivity.this, "Please enter ship/site name", Toast.LENGTH_LONG).show();
                else {
                    FileOutputStream out = openFileOutput("data.csv", Context.MODE_PRIVATE);
                    out.write((data.toString()).getBytes());
                    out.close();
                  //  Context context = getApplicationContext();

                    File locn = new File(getFilesDir(),"data.csv");// write in path SOC
                    Uri contentUri = FileProvider.getUriForFile(getApplicationContext(),"${applicationId}.fileprovider",locn);

                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/csv");
                    intent.putExtra(Intent.EXTRA_EMAIL, et_email.getText().toString());
                    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    intent.putExtra(Intent.EXTRA_STREAM, contentUri);
                    startActivity(Intent.createChooser(intent, "Pick an Email provider"));
                    Toast.makeText(MainActivity.this, "CSV created", Toast.LENGTH_LONG).show();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
评论