ArFragment仅显示闪烁的屏幕

时间:2019-05-22 02:14:31

标签: android kotlin augmented-reality arcore

我正在编写一个基本的ArCore应用程序。但是ArFragment仅在将其水平放置以检测平面时才显示闪烁的信号。另外,当我使用Sony experia测试时,缺少相机许可。我不确定我的手机是否受支持,因为我真的不知道手机的确切型号。以下是我的允许和一些初始化代码。

//Permission request

public boolean isCameraPermissionGranted(Activity host){
        // if the device isn't compatible return false
        if(!host.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA) &&
                !host.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_AR)){
            return false;
        }
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
                != PackageManager.PERMISSION_GRANTED) {

            // Permission is not granted
            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(host, Manifest.permission.CAMERA)) {
                // Show an explanation to the user *asynchronously* -- don't block
                // this thread waiting for the user's response! After the user
                // sees the explanation, try again to request the permission.
            } else {
                // No explanation needed; request the permission
                ActivityCompat.requestPermissions(host, new String[]{Manifest.permission.CAMERA},
                        MY_PERMISSIONS_REQUEST_CAMERA);
            }
        } else {
            // Permission has already been granted
            return true;
        }
        return false;
    }

//onCreate 
override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.image_activity_layout)

        utils  = Utils(applicationContext)
        if(utils.isCameraPermissionGranted(this) && utils.isStoragePermissionGranted(this))
            utils.maybeEnableAr()
        //loadCamera()

        arFragment = supportFragmentManager.findFragmentById(R.id.f_sceneform_fragment) as ArFragment
        // Adds a listener to the ARSceneView
        // Called before processing each frame
        arFragment.arSceneView.scene.addOnUpdateListener { frameTime ->
            arFragment.onUpdate(frameTime)
            //onUpdate()
        }

    }

//清单

<uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.ar" android:required="true"/>

//This the fragment
<fragment
            android:id="@+id/f_sceneform_fragment"
            android:name="com.google.ar.sceneform.ux.ArFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

这是我看到的屏幕。

enter image description here

1 个答案:

答案 0 :(得分:0)

添加了以下简单权限:

<uses-permission android:name="android.permission.CAMERA" />