vuforia sdk + android failed to initialize Vuforia with permission exception

本秂侑毒 提交于 2019-12-25 04:48:09

问题


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:


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.



来源:https://stackoverflow.com/questions/39386595/vuforia-sdk-android-failed-to-initialize-vuforia-with-permission-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!