알쓸전컴(알아두면 쓸모있는 전자 컴퓨터)

ARcore 기초 개념 (1) android version 본문

ARCore(google)

ARcore 기초 개념 (1) android version

백곳 2018. 12. 13. 22:30

ARcore 기초 개념 (1)


먼저 해당 자료는 AR 을 하기위한 구글 API 사용하기 위한 분석 자료로 사용 합니다.


참고 : https://developers.google.com/ar/develop/java/quickstart


1. 기본 환경

   - Install Android Studio version 3.1 or higher with Android SDK Platform version 7.0 (API level 24) or higher.

   설명을 보면 안드로이드 스튜디오는 3.1 버전 이상 부터 그리고 SDK API level 24 부터 사용 해야 된다고 한다.




2. 기본 셋팅


Add Sceneform to an existing projec


To use Sceneform in an existing project:

  1. Follow the steps to Enable ARCore in your app

  2. Add the Sceneform library to your app's build.gradle file:

    android {
       
    // Sceneform libraries use language constructs from Java 8.
       
    // Add these compile options if targeting minSdkVersion < 26.
        compileOptions
    {
            sourceCompatibility
    1.8
            targetCompatibility
    1.8
       
    }
    }

    dependencies
    {
       


       
    // Provides ArFragment, and other UX resources.
        implementation
    'com.google.ar.sceneform.ux:sceneform-ux:1.6.0'

       
    // Alternatively, use ArSceneView without the UX dependency.
        implementation
    'com.google.ar.sceneform:core:1.6.0'
    }
기본 셋팅을 하기 위해서는 build.gradle 을 위와 같이 라이브러리를 추가 해 줘야 합니다.

그리고 안드로이드에서는 2가지 타입의 설정이 존재 합니다 ..


There are two types of AR apps: AR Required and AR Optional.


AR Required  : Google Appstore 에 ARCore가 필수 적으로 설치 되어야 한다는 것과

AR Optional : ARCore 설치가 선택 적인것입니다 .
옵션 같은 경우는 ARcore 가 지원되지 않는 디바이스에서 사용 된다고 합니다.

ARCore의 경우 SDK 24 버전 이상 부터만 지원 됩니다.

ARcore 를 사용하는 입장에서 거의 AR Required 타입이지 않을까? 합니다.


<!-- "AR Required" apps must declare minSdkVersion ≥ 24 -->
<uses-sdk android:minSdkVersion="24" />

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

<!-- Indicates that app requires ARCore ("AR Required"). Ensures app is only
     visible in the Google Play Store on devices that support ARCore.
-->

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

<application>
    …
   
<!-- Indicates that app requires ARCore ("AR Required"). Causes Google
         Play Store to download and install ARCore when the app is installed.
    -->

   
<meta-data android:name="com.google.ar.core" android:value="required" />
</application>
위와 같이 설정 하면 Appstore 에 App을 올리면 ARcore가 설치가 안된 App은
ARCore가 자동으로 설치 됩니다.


그리고 build.gradle 파일을아래와 같이 사항을 체크하고 추가 하영 ㅑ합니다.

  • Make sure your project's build.gradle file includes Google's Maven repository:

    allprojects {
        repositories
    {
            google
    ()
           

  • Add the latest ARCore library as a dependency in your app's build.gradle file:

    dependencies {
       

        implementation
    'com.google.ar:core:1.6.0'
    }

그리고 Google 문서에서는 아래와 같이 카메라 권한을체크 해라 하고 되어 있지만
Sceneform 을 사용하면 자동으로 되니 깊게 생각 하지 않으셔도 될것 같습니다 .

@Override
protected void onResume() {
 
super.onResume();

 
// ARCore requires camera permission to operate.
 
if (!CameraPermissionHelper.hasCameraPermission(this)) {
   
CameraPermissionHelper.requestCameraPermission(this);
   
return;
 
}

 

}

Your AR activity must also implement onRequestPermissionsResult(…), as seen in HelloArActivity:

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results) {
 
if (!CameraPermissionHelper.hasCameraPermission(this)) {
   
Toast.makeText(this, "Camera permission is needed to run this application", Toast.LENGTH_LONG)
       
.show();
   
if (!CameraPermissionHelper.shouldShowRequestPermissionRationale(this)) {
     
// Permission denied with checking "Do not ask again".
     
CameraPermissionHelper.launchPermissionSettings(this);
   
}
    finish
();
 
}
}

그리고 Check ARCore install 이 되었지는 체크 하는 소스도 구글 문서에 있는데

AR Required  를 사용하면 굳이 체크할 필요가 없습니다.







Comments