2

I have imported the scanlibrary module in my app. This module has its own Manifest file with FileProvider.

This is the directory structure:

enter image description here

Below is my code to open the camera, and the Manifest files.

scanlibrary code to open camera and capture image

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;
    }

scanlibrary Manifest 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>

My app Manifest 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.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>

When I am running my app I am getting this error:

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)

My device is running Android version 10.

What is causing this error?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Ajinkya kadam
  • 542
  • 1
  • 6
  • 16

2 Answers2

0

I think you should merge the manifest files and should only provide one FIleprovider path. As seen your manifest files, you have two different fileprovider paths.

I have used this library, and i didnt import the project, rather i added the required files only, and it works perfectly fine for me.

nidhi
  • 29
  • 5
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/207085/discussion-on-answer-by-nidhi-couldnt-find-meta-data-for-provider-with-authorit). – Bhargav Rao Feb 03 '20 at 07:04
0

i've added the fix, and now the issue is solved. the reason you were getting error is mentioned below:

you had to change this to

<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>

to

<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>

Also, i am assuming that you have knowledge about ndk android, so you might have added the required ndk setup for your android studio and machine. if not, you should first checkout the basics for same.

So, if ndk is setup properly, you will be able to generate .so files required for native methods in class ScanActivity.

At present, i have added

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

in local.properties file and compiled .h files to generate .so files..so your code is working perfectly now. So, you will need to add your local machine path to your ndk-bundle as above.

here is the full project link

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

Thanks

nidhi
  • 29
  • 5
  • Hi Nidhi, i have imported your project and changed ndk path also but i am getting error. i have sent you in chat. can you please check – Ajinkya kadam Feb 03 '20 at 09:50
  • here is the chat link address https://chat.stackoverflow.com/rooms/207085/discussion-on-answer-by-nidhi-couldnt-find-meta-data-for-provider-with-authorit – Ajinkya kadam Feb 03 '20 at 09:50