0

App crashes after running the program with failed to initialize Vuforia with permission exception

Android version is <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />

testing on device 4.1.1 (api level 16) with front camera only.

Permission included in manifest file:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-feature android:glEsVersion="0x00020000" />

exception at SampleApplicationSession's InitVuforiaTask Task, value of Vuforia.init() returned is -1.

Not sure what I missed.

Library included are armaebi-v7a/libVuforia.so, android-support-v4, jpct_ae, Vuforia

Tom11
  • 2,419
  • 8
  • 30
  • 56
vims liu
  • 643
  • 1
  • 9
  • 20
  • I have the same error when I am using unity to build AR app in android ' actually I have created a android plugin and changed the android manifest file and forgot to add permission for camera usage as unity merge your created manifest file with original manifest that created the conflict, adding camera permission solve mine problem. "I came to know about this problem after using android monitor of android studio". – Aryaman Gupta May 04 '17 at 17:35

1 Answers1

1

I have faced the same problem. If you see the example comes with the compiledSdKversion 22 because in newer versions the user have to explicitly give the Camera permission. My project is working with API 25 by adding some code to my android application. In my case, I asked for the Camera Permission before opening the vuforia activity when an user clic a FloatingActionButton:

FloatingActionButton flb=(FloatingActionButton)findViewById(R.id.floatingActionButton2);
    flb.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


            if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
            }
            else
            {
                Intent myIntent = new Intent(MainActivity.this, VideoPlayback.class);
                startActivity(myIntent);
            }

        }
    });

The VideoPlayback is the activity that use AR from vuforia included in the advance examples. In this case you have to listen to an onRequestPermissionsResult because we have to check the user's answer.

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    // Begin monitoring for Aruba Beacon-based Campaign events
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    if (requestCode == 0) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED
                && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
            Intent myIntent = new Intent(MainActivity.this, VideoPlayback.class);
            startActivity(myIntent);
        }
    }


}

In the onRequestPermissionsResult we check if the answer was positive an if so we open the activity.

I hope it works for you too.

Kevin Sanchez
  • 2,215
  • 2
  • 11
  • 19