Couldn't find meta-data for provider with authority

后端 未结 10 1233
粉色の甜心
粉色の甜心 2020-12-05 10:12

I have integrated Snapchat\'s Creative Kit in my Android app. After processing, I receive an image from the server in the form of Byte Array which I am saving to the disk an

相关标签:
10条回答
  • 2020-12-05 10:39
        <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/file_paths"></meta-data>
        </provider>
    

    This is my provider declaration, the value of ${applicationId} is "com.limxtop.research", make sure that the name of authorities is the same with that of the codes below.

                // Create the file where the photo should save.
                File file = null;
                try {
                    file = createImageFile();
                } catch (IOException e) {
                    break;
                }
                // The second parameter is the name of authorities.
                Uri uri = FileProvider.getUriForFile(this,
                        "com.limxtop.research.fileprovider", file);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                        | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                startActivityForResult(intent, fullSizeRequestCode);
    

    So, maybe your codes post here is not complete, there you should pass "my.package.name.fileprovider" as parameter some where.

    0 讨论(0)
  • 2020-12-05 10:42

    Its fileprovider and not provider

    android:authorities="${applicationId}.fileprovider"
    
    0 讨论(0)
  • 2020-12-05 10:43

    I just removed the '$' from android:authorities="${applicationId}.provider" and it works like a charm now.

    0 讨论(0)
  • 2020-12-05 10:45

    First write the following tag in manifest under the Tag

     <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/provider_paths" />
            </provider>
    

    Then Create a xml folder in res and create a file names: provide+paths.xml and then copy paste the code:

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

    and now most developer mistake in programs to create File in program then we will use:

    FileProvider.getUriForFile(Objects.requireNonNull(getApplicationContext()),
                        BuildConfig.APPLICATION_ID + ".provider", file);
    

    Hope this will work for yor !!!

    0 讨论(0)
  • 2020-12-05 10:48

    {applicationId} == com.companyName.application append ".provider"

    which will be == com.example.test.provider

    in xml authorities:com.example.test.provider

    in activity Uri mPath = FileProvider.getUriForFile(this, "com.example.example.provider", imageFile);

    0 讨论(0)
  • 2020-12-05 10:48

    The problem here is, you use the class name .provider for authorities in manifest and use .fileprovider class name in java code.

     <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/provider_paths_app" />
        </provider>
    
    
    
    Couldn't find meta-data for provider with authority my.package.name.fileprovider
    

    Just rename fileprovider to provider

    0 讨论(0)
提交回复
热议问题