gpt4 book ai didi

android - AR 应用程序不工作显示错误 "Failed to create AR session"

转载 作者:行者123 更新时间:2023-12-05 06:19:06 27 4
gpt4 key购买 nike

这是我的主要代码

package com.example.ar;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.widget.Toast;

import com.google.ar.core.Anchor;
import com.google.ar.core.HitResult;
import com.google.ar.core.Plane;
import com.google.ar.sceneform.AnchorNode;
import com.google.ar.sceneform.rendering.ModelRenderable;
import com.google.ar.sceneform.ux.ArFragment;
import com.google.ar.sceneform.ux.TransformableNode;

public class MainActivity extends AppCompatActivity
{
private static final String TAG = MainActivity.class.getSimpleName();
private static final double MIN_OPENGL_VERSION = 3.0;
ArFragment arFragment;
ModelRenderable lampPostRenderable;
@Override
@SuppressWarnings({"AndroidApiChecker", "FutureReturnValueIgnored"})

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!checkIsSupportedDeviceOrFinish(this))
{
return;
}
setContentView(R.layout.activity_main);
arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
ModelRenderable.builder().setSource(this, Uri.parse("lamppost.sfb")).build()
.thenAccept(renderable -> lampPostRenderable = renderable)
.exceptionally(throwable ->
{
Toast toast = Toast.makeText(this, "Unable to load andy renderable",
Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
}
);
arFragment.setOnTapArPlaneListener((HitResult hitresult, Plane plane, MotionEvent motionevent) -> {
if (lampPostRenderable == null){
return; }
Anchor anchor = hitresult.createAnchor();
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arFragment.getArSceneView().getScene());
TransformableNode lamp = new TransformableNode(arFragment.getTransformationSystem());
lamp.setParent(anchorNode);
lamp.setRenderable(lampPostRenderable);
lamp.select();
});
}

public static boolean checkIsSupportedDeviceOrFinish(final Activity activity)
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
{
Log.e(TAG, "Sceneform requires Android N or later");
Toast.makeText(activity, "Sceneform requires Android N or later", Toast.LENGTH_LONG).show();
activity.finish();
return false;
}
String openGlVersionString =
((ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE))
.getDeviceConfigurationInfo().getGlEsVersion();
if (Double.parseDouble(openGlVersionString) < MIN_OPENGL_VERSION)
{
Log.e(TAG, "Sceneform requires OpenGL ES 3.0 later");
Toast.makeText(activity, "Sceneform requires OpenGL ES 3.0 or later", Toast.LENGTH_LONG).show();
activity.finish();
return false;
}
return true;
}
}

我还包括了

 <meta-data
android:name="com.google.ar.core"
android:value="required" />

在 Android list 文件中。

Gradle module:app有

 implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.15.0'

gradle项目有

 classpath 'com.google.ar.sceneform:plugin:1.5.0'

在依赖中。

我的 sampledata 文件夹有一个 obj 和一个名为 lamppost 的 mtl 文件。

打开应用程序时,错误显示为“创建 AR session 失败”带有黑色屏幕和手持设备绕圈旋转的动画 here's how it looks like .

最佳答案

在我的例子中,我忘记在 list 文件中包含以下代码

    <meta-data
android:name="com.google.ar.core"
android:value="required" />

这是我的完整 list 文件

<?xml version="1.0" encoding="utf-8"?>

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

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

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

<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.ar.core"
android:value="required" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

希望对您有所帮助!谢谢!

关于android - AR 应用程序不工作显示错误 "Failed to create AR session",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60970778/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com