vuforia sdk + android无法以权限异常初始化Vuforia [英] vuforia sdk + android failed to initialize Vuforia with permission exception

查看:164
本文介绍了vuforia sdk + android无法以权限异常初始化Vuforia的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行程序后初始化失败,导致应用程序崩溃 Vuforia具有权限例外

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

Android版本为<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />

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

仅在使用前置摄像头的设备4.1.1(api级别16)上进行测试.

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" />

任务中SampleApplicationSession

例外,返回的Vuforia.init()值为-1.

不确定我错过了什么.

包含的库是armae​​bi-v7a/libVuforia.so,android-support-v4,jpct_ae,Vuforia

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

推荐答案

我也遇到了同样的问题.如果您看到该示例,则该文件随带编译的SdKversion 22,因为在较新的版本中,用户必须显式授予Camera权限.我的项目通过向我的android应用程序中添加一些代码来使用API​​ 25.就我而言,当用户单击FloatingActionButton时,我在打开vuforia活动之前要求提供摄像头许可":

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);
            }

        }
    });

VideoPlayback是使用高级示例中包含的来自vuforia的AR的活动.在这种情况下,您必须收听onRequestPermissionsResult,因为我们必须检查用户的答案.

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);
        }
    }


}

在onRequestPermissionsResult中,我们检查答案是否定的,如果是,则我们打开活动.

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

我希望它也对您有用.

这篇关于vuforia sdk + android无法以权限异常初始化Vuforia的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆