Cordova Android Camera- giving illegal argument exception
Asked Answered
O

5

20

I started cordova Android programming 2 month back. Everything was fine mainly camera that is not working now. But last week some how my project directory got deleted and I reinstall all plugin of cordova and complied project but now its showing error 'illegal argument exception' on camera click surprising thing is i didn't change single line of code and it's also working properly on other developer machine.

cordova plugin add cordova-plugin-camera command used from camera plugin installation.

camera_app.js file

var pictureSource; // picture source
var destinationType; // sets the format of returned value


// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available
//
function onDeviceReady() {
    pictureSource = navigator.camera.PictureSourceType;
    destinationType = navigator.camera.DestinationType;

}


// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
    // largeImage.src = imageURI;
    console.log(imageURI);
    console.log(document_type);


}

function getPhoto(docType) {
    // Retrieve image file location from specified source
    document_type = docType
    $('.docError').hide();
    navigator.camera.getPicture(onPhotoURISuccess, onFail, {
        quality: 50,
        destinationType: destinationType.FILE_URI
    });
}


$('#file1').click(function() {
    console.log('On camera click');
    getPhoto("addressProof");
});

I tried to debug code finally found it's due to provider path- java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data

but I have already added provider path meta data in Android xml file, as its automatically gets added when you add cordova plugin.

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

cordova plugin -

cordova-plugin-app-version 0.1.9 "AppVersion" cordova-plugin-camera 2.4.1 "Camera" cordova-plugin-compat 1.1.0 "Compat" cordova-plugin-whitelist 1.3.2 "Whitelist" cordova-sqlite-storage 1.4.9 "Cordova sqlite storage plugin" ionic-plugin-keyboard 2.2.1 "Keyboard"

cordova platform-

Installed platforms: android 6.2.3 Available platforms: blackberry10 ~3.8.0 (deprecated) browser ~4.1.0 webos ~3.7.0 windows ~5.0.0

NPM version- { npm: '3.10.3', ares: '1.10.1-DEV', http_parser: '2.7.0', icu: '57.1', modules: '48', node: '6.4.0', openssl: '1.0.2h', uv: '1.9.1', v8: '5.0.71.60', zlib: '1.2.8' }

Orr answered 28/2, 2017 at 7:18 Comment(25)
did you tried removing and re-adding thr android platform? This definitely cant be the plugin issue as i dont see any issue related to this in their offical bug tracker. More of an environment issueRyals
cordova-android version? cordova CLI version?Singular
@Singular cordova version 7.0.1Orr
how is the cordova-plugin-camera entry in your config.xml?Singular
@Singular yes it's already there.Orr
I mean how? can you copy it and paste on the question?Singular
also, can you run cordova plugins and cordova platforms and put the results on the question?Singular
@Singular please check requested details in questionOrr
I'm not been able to reproduce your problem on Android 6 and Android 7 devices. In which Android version are you testing? Can you try doing a cordova platform rm android and then cordova platform add android?Singular
@Singular I already did it but it's still giving same error. even I uninstall cordova and reinstall again and tried but same errorOrr
looks like a really strange edge case, I'm not able to reproduce and you say that it works on other developer machine, so might be something related to your machine. Which node/npm versions are you using?Singular
on which device do you get this error?Belostok
@Singular I have added npm version in question, please checkOrr
@MaximShoustin this error is not on specific device, it's getting on device when I run application from my system. Interestingly it's not getting on on my colleague system. Do you think any configuration specific error related to my project on system?Orr
@Orr I believe it can be refer to specific device or sdk versionBelostok
@MaximShoustin I have tried it on different device and sdk version as well but same result. I am thinking with something issue with project configuration. Because I have created separate sample for camera and its working properly.Orr
@Orr please post your project to github to let us debug itBelostok
@MaximShoustin Finally am able solve it. ohh God.Orr
@Orr What was the environment issue?Ryals
@MaximShoustin I have added answer to question, hope It will others all well.Orr
@MaximShoustin I am searching for solution from last 4 months. I was using my colleague desktop generate apk and finally am able solve it. I have added and remove cordova camera plugin at least 50 to 60 times still I didn't find solutionOrr
@Orr It took four months since you have not provided the complete info for the users. Especially this question has appeared in featured questions twice and its so unfortunate that it had enough info for anyone to figure out the problem.Ryals
@Ryals Yes it was unfortunate for me as well. But none of users has ask me for Android manifest.Orr
@Orr As you have posted only the excerpt of the file, everyone would assume its fine. I m telling this to you so that you can be extra careful while posing questions in the future with more info especially the feature questions. This will help everyone and you can get a quicker solution.Ryals
@Ryals Thanks. I will always take care of it in future.Orr
O
8

It was very simple and basic. Just add your file provider below to your cordova launcher activity. In my case I was having some custom activity and by mistake provider was added at bottom of all activity and my guess is cordova not able to read that provider that's why it was giving java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data

Orr answered 20/9, 2017 at 19:1 Comment(9)
But you have mentioned that you have not made any code change in the project since the working copy. So where does the custom activity came from? Also you have mentioned that the android manifest file was all properRyals
@Ryals As android developer I thought once declare provider in your manifest code and read it from any where but not was not case in cordova. you can try in your project and look what will happen.Orr
The manifest file in auto generated on android build. So will never tweak that to test anything. You could have posted the androidmanifest file well in advanceRyals
@Ryals yes bro I should have posted it here but it was working earlier properly even if I have edited Android manifest.Orr
please dont edit manifest file directly as it will get overwritten on subsequent android builds. You can use plugins to tranfer such info from config.xml to manifest file during buildRyals
Yes I will take care of itOrr
Ended up spending a day cracking this earlier but in vain. Anyways glad that you cracked it finally. CheersRyals
what does it really mean to add your file provider below to your cordova launcher activity? Im a beginner in cordovaVantage
@Vantage It means do not change anything in manifest. Android Manifest is autogenerate in cordova app.Orr
B
0

I had a similar problem today. Tried everything (reinstall plugin, reinstall plugin from source, reinstall older version of plugin) but nothing seemed to help. Don't know why but after - killing the emulator - > cordova clean android - > cordova platform remove android - > cordova platform add android - > cordova build android - connecting my device - > cordova run android it works again as before :-) I still don't know why. Try it on your own risk. Maybe it helps.

Befitting answered 21/3, 2017 at 22:10 Comment(0)
C
0

Make sure your Android Virtual Device Emulator has a Front and Back Camera set! I had also the same error and removing and adding platforms did not work.

Sidenote: For the Emulator to work, you need to have him already open and then you could run your Debug APK from Android Studio 3.3 or run `ionic cordova run android`.

What worked: Open Android Virtual Device Manager (Android Studio -> Configure -> AVD Manager)

enter image description here

Actions -> Edit (Pencil Icon)

enter image description here

Show Advanced Settings

enter image description here

Make sure you did add a Front and Back camera! Before this setting was "None", so this did not work and I got the errors above. After adding the camera, everything worked.

Hopefully this will help someone like me, who had an AVD configured without a camera.

Casper answered 14/2, 2019 at 20:41 Comment(0)
R
0

There are two ways to resolve the problem.

  1. There might be a miss-match with the provider name in AndroidManifest.xml (Package= / ApplicationId)

  2. Second way In your build.gradle (app) file

    release {... minifyEnabled false ...}

Rogovy answered 21/11, 2021 at 11:55 Comment(0)
A
0

It is working after changing the applicationId to app package id in "CameraLancher.java"

public void takePicture(int returnType, int encodingType)
    {
        // Save the number of images currently on disk for later
        this.numPics = queryImgDB(whichContentStore()).getCount();

        // Let's use the intent and see what happens
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        // Specify file so that large image is captured and returned
        File photo = createCaptureFile(encodingType);
        this.imageFilePath = photo.getAbsolutePath();
        this.imageUri = FileProvider.getUriForFile(cordova.getActivity(),
                "com.package-id" + ".cordova.plugin.camera.provider", ---->> your app package id
                photo);
Arthro answered 26/2, 2022 at 20:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.