ArFragment отображает только мигающий экран - PullRequest
0 голосов
/ 22 мая 2019

Я пишу базовое приложение 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 голосов
/ 25 мая 2019

Добавлено простое разрешение:

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