无法找到具有权限 com.scanlibrary.provider 的提供商的元数据

问题描述 投票:0回答:2

我已在我的应用程序中导入了

scanlibrary
模块。该模块有自己的清单文件,带有
FileProvider

这是目录结构:

下面是我打开相机的代码和清单文件。

扫描库代码打开相机并捕获图像

public final static int PICKFILE_REQUEST_CODE = 1;
public final static int START_CAMERA_REQUEST_CODE = 2;
public final static String OPEN_INTENT_PREFERENCE = "selectContent";
public final static String IMAGE_BASE_PATH_EXTRA = "ImageBasePath";
public final static int OPEN_CAMERA = 4;
public final static int OPEN_MEDIA = 5
public final static String SCANNED_RESULT = "scannedResult";
public final static String IMAGE_PATH = Environment
            .getExternalStorageDirectory().getPath() + "/scanSample";

public final static String SELECTED_BITMAP = "selectedBitmap";


public void openCamera() {
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        File file = createImageFile();
        boolean isDirectoryCreated = file.getParentFile().mkdirs();
        Log.d("", "openCamera: isDirectoryCreated: " + isDirectoryCreated);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            Uri tempFileUri = FileProvider.getUriForFile(getActivity().getApplicationContext(),
                    "com.scanlibrary.provider", // As defined in Manifest
                    file);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempFileUri);
        } else {
            Uri tempFileUri = Uri.fromFile(file);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempFileUri);
        }
        startActivityForResult(cameraIntent, ScanConstants.START_CAMERA_REQUEST_CODE);
    }

    private File createImageFile() {
        clearTempImages();
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new
                Date());
        File file = new File(ScanConstants.IMAGE_PATH, "IMG_" + timeStamp +
                ".jpg");
        fileUri = Uri.fromFile(file);
        return file;
    }

扫描库清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.scanlibrary" >
    <uses-sdk android:targetSdkVersion="28" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <application
        android:allowBackup="true"
        android:largeHeap="true"
        android:hardwareAccelerated="true"
        android:label="@string/app_name" >
        <activity
            android:name=".ScanActivity"
            android:configChanges="orientation|screenSize"
            android:label="@string/app_name" >
        </activity>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.scanlibrary.provider"
            android:exported="false"
            android:grantUriPermissions="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>
    </application>

</manifest>

我的应用程序清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.notepad.cuecardsnotes">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name="com.notepad.cuecardsnotes.DocScanning"></activity>
    <activity
        android:name="com.notepad.cuecardsnotes.MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.notepad.cuecardsnotes.AllNotes"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.notepad.cuecardsnotes.OpenNotes"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize" />
    <activity
        android:name="com.notepad.cuecardsnotes.CreateNotes"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize" />

    <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.notepad.cuecardsnotes.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true"
        tools:replace="android:authorities">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            tools:replace="android:resource"
            android:resource="@xml/filepaths" />
    </provider>
</application>

</manifest>

当我运行我的应用程序时,我收到此错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.notepad.cuecardsnotes/com.scanlibrary.ScanActivity}: java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.scanlibrary.provider
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3374)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3513)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2109)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
     Caused by: java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.scanlibrary.provider
        at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:606)
        at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:579)
        at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:417)
        at com.scanlibrary.PickImageFragment.openCamera(PickImageFragment.java:121)
        at com.scanlibrary.PickImageFragment.handleIntentPreference(PickImageFragment.java:77)
        at com.scanlibrary.PickImageFragment.init(PickImageFragment.java:58)
        at com.scanlibrary.PickImageFragment.onCreateView(PickImageFragment.java:48)
        at android.app.Fragment.performCreateView(Fragment.java:2534)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1303)
        at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431)
        at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210)
        at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166)
        at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067)
        at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3057)
        at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3004)
        at android.app.FragmentController.dispatchActivityCreated(FragmentController.java:184)
        at android.app.Activity.performCreate(Activity.java:7822)
        at android.app.Activity.performCreate(Activity.java:7804)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1318)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3349)

我的设备运行的是 Android 版本 10。

导致此错误的原因是什么?

android android-camera android-manifest android-fileprovider
2个回答
0
投票

我认为你应该合并清单文件并且应该只提供一个 FIleprovider 路径。 正如您的清单文件所示,您有两个不同的文件提供程序路径。

我已经使用了这个库,并且我没有导入该项目,而是仅添加了所需的文件,它对我来说工作得很好。


0
投票

我已添加修复程序,现在问题已解决。 下面提到了您收到错误的原因:

你必须将其更改为

<com.scanlibrary.PolygonView
            android:id="@+id/polygonView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:visibility="gone"></com.scanlibrary.PolygonView>

<com.reminder.testapplication.PolygonView
            android:id="@+id/polygonView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:visibility="gone"></com.reminder.testapplication.PolygonView>

另外,我假设您了解有关 ndk android 的知识,因此您可能已经为您的 android studio 和机器添加了所需的 ndk 设置。如果没有,您应该首先检查相同的基础知识。

因此,如果 ndk 设置正确,您将能够生成 ScanActivity 类中的本机方法所需的 .so 文件。

目前我已经添加了

ndk.dir=C\:\\Users\\Kalp007\\AppData\\Local\\Android\\Sdk\\android-ndk-r20b

在 local.properties 文件中并编译 .h 文件以生成 .so 文件。所以您的代码现在可以完美运行。 因此,您需要将本地计算机路径添加到您的 ndk-bundle 中,如上所述。

这是完整的项目链接

https://drive.google.com/file/d/1qMth1ahk3zXhk0CDeRlP-WiTq8zwsu3e/view?usp=sharing

谢谢

© www.soinside.com 2019 - 2024. All rights reserved.