Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After open the camera i get "Illegal Argument Exception". #689

Closed
3 tasks done
jonapachanga opened this issue Nov 18, 2020 · 19 comments
Closed
3 tasks done

After open the camera i get "Illegal Argument Exception". #689

jonapachanga opened this issue Nov 18, 2020 · 19 comments

Comments

@jonapachanga
Copy link

Bug Report

openCamera() {
    const options: CameraOptions = {
      quality: 100,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE
    };

    this.camera.getPicture(options).then((imageData) => {
      console.log(imageData);
    }, (err) => {
      console.log(err);
    });
  }

This is my code. It's very simple, I tried on Android 9 and Android 10, Also i played with the different CameraOptions but always i get "Illegal Argument Exception"

Problem

What is expected to happen?

I have expected the camera open

What does actually happen?

Throw the error Illegal Argument Exception

Information

The followings are part of my package.json

"dependencies": {
    "@angular/common": "~9.1.6",
    "@angular/core": "~9.1.6",
    "@angular/forms": "~9.1.6",
    "@angular/platform-browser": "~9.1.6",
    "@angular/platform-browser-dynamic": "~9.1.6",
    "@angular/router": "~9.1.6",
    "@auth0/angular-jwt": "^5.0.1",
    "@capacitor/android": "^2.2.1",
    "@capacitor/core": "2.2.1",
    "@ionic-native/android-permissions": "^5.28.0",
    "@ionic-native/badge": "^5.27.0",
    "@ionic-native/base64": "^5.28.0",
    "@ionic-native/camera": "^5.29.0",
    "@ionic-native/core": "^5.0.7",
    "@ionic-native/device": "^5.27.0",
    "@ionic-native/diagnostic": "^5.27.0",
    "@ionic-native/downloader": "^5.28.0",
    "@ionic-native/file": "^5.27.0",
    "@ionic-native/file-chooser": "^5.27.0",
    "@ionic-native/file-opener": "^5.27.0",
    "@ionic-native/file-path": "^5.27.0",
    "@ionic-native/file-picker": "^5.27.0",
    "@ionic-native/file-transfer": "^5.27.0",
    "@ionic-native/image-picker": "^5.27.0",
    "@ionic-native/local-notifications": "^5.27.0",
    "@ionic-native/media": "^5.27.0",
    "@ionic-native/media-capture": "^5.27.0",
    "@ionic-native/push": "^5.27.0",
    "@ionic-native/social-sharing": "^5.27.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic-native/video-editor": "^5.28.0",
    "@ionic/angular": "^5.0.0",
    "aws-sdk": "^2.739.0",
    "com-badrit-base64": "^0.2.0",
    "cordova-plugin-android-permissions": "^1.0.2",
    "cordova-plugin-badge": "^0.8.8",
    "cordova-plugin-camera": "^5.0.1",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-file-opener2": "^3.0.4",
    "cordova-plugin-file-transfer": "^1.7.1",
    "cordova-plugin-filechooser": "^1.2.0",
    "cordova-plugin-filepath": "^1.5.8",
    "cordova-plugin-filepicker": "^1.1.6",
    "cordova-plugin-local-notification": "^0.9.0-beta.2",
    "cordova-plugin-media": "^5.0.3",
    "cordova-plugin-media-capture": "^3.0.3",
    "cordova-plugin-telerik-imagepicker": "^2.3.3",
    "cordova-plugin-video-editor": "^1.1.3",
    "cordova-plugin-x-socialsharing": "^5.6.8",
    "cordova.plugins.diagnostic": "^6.0.2",
    "date-fns": "^2.15.0",
    "es6-promise-plugin": "^4.2.2",
    "google-libphonenumber": "^3.2.11",
    "integrator-cordova-plugin-downloader": "^1.1.0",
    "ionic2-calendar": "^0.6.6",
    "jetifier": "^1.6.6",
    "jssha": "^3.1.1",
    "ng2-currency-mask": "^9.0.2",
    "phonegap-plugin-multidex": "^1.0.0",
    "phonegap-plugin-push": "^2.3.0",
    "rxjs": "~6.5.1",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.901.5",
    "@angular/cli": "~9.1.5",
    "@angular/compiler": "~9.1.6",
    "@angular/compiler-cli": "~9.1.6",
    "@angular/language-service": "~9.1.6",
    "@capacitor/cli": "2.2.1",
    "@ionic/angular-toolkit": "^2.1.1",
    "@types/google-libphonenumber": "^7.4.19",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/jssha": "^2.0.0",
    "@types/node": "^12.12.54",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3"
  },
  "description": "An Ionic project"
}

Environment, Platform, Device

I am running Ionic CLI 6.10.1 with Capacitor - Angular CLI 9.0.6

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@jonapachanga jonapachanga changed the title Before open the camera i get "Illegal Argument Exception". After open the camera i get "Illegal Argument Exception". Nov 18, 2020
@naitikpatel1990
Copy link

Getting same issue. Tried every possible way for it. But seems crashed inn native code. Please Help us in to that.

Thank you

@breautek
Copy link
Contributor

Can someone let me know if the error goes away if <preference name="android-targetSdkVersion" value="28" /> is used?

Note that targeting API 28 won't be google play store compliant but will tell us if this is a problem introduced by an android API change.

@naitikpatel1990
Copy link

@breautek

After add that still getting same error.

@breautek
Copy link
Contributor

Thanks for trying.

We'll probably will require a Sample Reproduction App to move this issue along.

@jonapachanga
Copy link
Author

Hi, I created a Sample Reproduction App as suggested by @breautek and to my surprise the plugin works fine. The only difference is the version of the plugin, in my project i have:

"@ionic-native/camera": "^5.29.0"
"cordova-plugin-camera": "^5.0.1"

And the new one

"@ionic-native/camera": "^5.30.0"
"cordova-plugin-camera": "^5.0.1"

i updated my project but it still doesn't work. Are there any plugin what interfere with camera plugin?

the strange thing is that when I use the plugin to select an image from the gallery it works fine

@naitikpatel1990
Copy link

@jonapachanga

I suspect that latest plugin is getting same error with ionic 5 version.

I do have same plugin in ionic 4 working fine.

Can you confirm on that?

@PieterVanPoyer
Copy link
Contributor

@jonapachanga can you add a stacktrace? I am not sure if it is a Javascript exception or a native plugin exception.

@naitikpatel1990
Copy link

@PieterVanPoyer

Might be following might help to identified issue:

Screenshot 2021-01-09 at 11 11 54 AM

FYI: Permission for camera is given manually. First time camera permission was not asked and app is just crashed. Something really missing or crashed.

@naitikpatel1990
Copy link

naitikpatel1990 commented Jan 9, 2021

Hey,

I fixed by changed some code in CameraLauncher.java file but it's not proper as i did hardcoded there.

in public void takePicture(int returnType, int encodingType) method has following code:

this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
                applicationId + ".provider",
                photo));

here somehow in ionic 5 applicationId got not found and throwing that error.

so for now i hard coded like following:

this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
                 "my.application.packgeID.provider", // my.application.packgeID is my app package id 
                photo));

and bingo it's working.

But we need proper solution to grab package id there it's not dynamic for now as i don't know it's ionic 5 issue or plugin code issue till now. :)

Thank you

@PieterVanPoyer
Copy link
Contributor

PieterVanPoyer commented Jan 9, 2021

Strange. Normally there is a BuildConfig.class generated. (Not the one under org.apache.cordova)

The applicationId is read from the BuildConfig in the CameraLauncer.
image

image

Is the BuildConfig class generated when you run your app?
What is the content of it? Can you share a screenshot?

@naitikpatel1990
Copy link

@PieterVanPoyer

that can be happened and missed packageID in my code either of following reasons:

  1. I did changed my packageID and uninstall and install platform in ionic after that or

  2. we are on IONIC 5 where it was not working. FYI: in ionic 4 with same plugin i can able to open camera without any changes in plugin what i did above.

Above might help you to identified issue.

@PieterVanPoyer
Copy link
Contributor

@naitikpatel1990 can you search for a BuildConfig class in your project? Like in my screenshot? Is it present in your project after building or during debugging?

@PieterVanPoyer
Copy link
Contributor

Is this issue still present. If it is not reproducable in a plain Cordova app, we won't be able to help.

If the issue is solved, please close it.

@PieterVanPoyer
Copy link
Contributor

@naitikpatel1990 Is this issue still present. If it is not reproducable in a plain Cordova app, we won't be able to help and need to close this issue.

If the issue is solved, please close it.

@naitikpatel1990
Copy link

@PieterVanPoyer

Issue is not opened by me so i can't close it.

Regarding issue i gave all possible ways i tried and it seems working for me. So not gonna make sample app and integrate as too much overloaded with other tasks for now.

@PieterVanPoyer
Copy link
Contributor

@naitikpatel1990 thanks for the info. Indeed you did not open this issue.

@jonapachanga Is this issue still present with the latest camera version (v5.0.2)? If it is not reproducable in a plain Cordova app, we won't be able to help and need to close this issue.

If the issue is solved, please close it.

@PieterVanPoyer
Copy link
Contributor

Issue is being closed due to missing reproduction cordova app.

@MattSynaptic
Copy link

Hey,

I fixed by changed some code in CameraLauncher.java file but it's not proper as i did hardcoded there.

in public void takePicture(int returnType, int encodingType) method has following code:

this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
                applicationId + ".provider",
                photo));

here somehow in ionic 5 applicationId got not found and throwing that error.

so for now i hard coded like following:

this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
                 "my.application.packgeID.provider", // my.application.packgeID is my app package id 
                photo));

and bingo it's working.

But we need proper solution to grab package id there it's not dynamic for now as i don't know it's ionic 5 issue or plugin code issue till now. :)

Thank you

This worked for me but I figured out if you do this it will resolve it without having to hard-code the applicationId in:

    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        this.callbackContext = callbackContext;

        //Adding an API to CoreAndroid to get the BuildConfigValue
        //This allows us to not make this a breaking change to embedding
        // BROKEN: this.applicationId = (String) BuildHelper.getBuildConfigValue(cordova.getActivity(), "APPLICATION_ID");
        // BROKEN: this.applicationId = preferences.getString("applicationId", this.applicationId);
        this.applicationId = cordova.getActivity().getPackageName(); // ADDED

@m30102
Copy link

m30102 commented Oct 19, 2021

why not use cxt.getPackageName? image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants