vuforia sdk + android failed to initialize Vuforia

2019-09-11 06:52发布

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

1条回答
等我变得足够好
2楼-- · 2019-09-11 07:40

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.

查看更多
登录 后发表回答