# Android 기초 설정

가장 먼저 푸시 발송을 위한 필수 설정을 위해 아래의 두 가지를 순서대로 진행 해 주세요.

1. **FCM 인증서 설정**

{% embed url="<https://document.wisetracker.co.kr/v/v2-developer/push/android/fcm_setting>" %}

2. **대시보드 설정**

{% embed url="<https://document.wisetracker.co.kr/v/v2-developer/push/android/dashboardsetting>" %}

### SDK 설치&#x20;

#### **`프로젝트 build.gradle`**

프로젝트의 build.gradle ( root 파일 ) 에 아래와 같이 repository 주소를 추가해주세요.

{% tabs %}
{% tab title="build.gradle(root)" %}

```gradle
...
allprojects {
    repositories {
        google()
        mavenCentral() 
         /* wisetracker sdk repository config */
        maven {
            def endPoint = "https://analytics.wisetracker.co.kr/console/android/sdk/github/credentials.do"
            url = uri(new URL(endPoint+'?name=URI').text)
            credentials {
                username = new URL(endPoint+'?name=USER').text
                password = new URL(endPoint+'?name=TOKEN').text
            }
        }
    }
}
...
buildscript {
  repositories {
    google()
    mavenCentral()
  }
  dependencies {
    ...
    /* Google services */
    classpath 'com.google.gms:google-services:4.3.15'  // Google Services plugin
    ...
  }
}
```

{% endtab %}
{% endtabs %}

#### **`Android 13 이상의 버전에서 푸시 알림 권한 획득을 위한 설정`**

`프로젝트 수준 혹은, app 수준 "build.gradle"의 "`targetSdkVersion = 33" 이상이어야 합니다.

```groovy
buildscript {
    ext {
        ...
        targetSdkVersion = 33
        ...
```

#### **`app모듈 build.gradle`**

프로젝트의 app/build.gradle 파일에 있는 `dependencies`에 아래와 같이 Wisetracker SDK를 추가해주세요.

<mark style="color:orange;">**`이 때, Java와 Kotlin에 따라 이용하는 모듈명이 달라집니다.`**</mark>

{% tabs %}
{% tab title="gradle-Java" %}

```gradle
...
// 1. Google Services plugin 추가
apply plugin: 'com.google.gms.google-services'  
...

android {
  ...
}
...
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    ....
    // 2. Wisetracker SDK 적용
     implementation "com.sdk.wisetracker:base_module:latest.release"
     implementation "com.sdk.wisetracker:new_dot_module:latest.release"
    
    // 3. Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:29.0.0')
    
    // 4. Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-messaging'
}
...
```

{% endtab %}

{% tab title="gradle-Kotlin" %}

```kotlin
...
// 1. Google Services plugin 추가
apply plugin: 'com.google.gms.google-services'  
...

android {
  ...
}
...
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    ....
    // 2. Wisetracker SDK 적용
    implementation "com.sdk.wisetracker:base_module:1.0.78"
    implementation "com.sdk.wisetracker:new_dot_module:1.0.47"
    
    // 3. Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:29.0.0')
    
    // 4. Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-messaging-ktx'
}
...
```

{% endtab %}
{% endtabs %}

### AuthorizationKey 등록

{% hint style="warning" %}
AuthorizationKey 등록은 Wisetracker 기본 SDK가 이미 적용된 경우에는 다시 적용할 필요가 없습니다. 메시징 서비스만 이용하는 경우 등록 해 주세요.
{% endhint %}

#### **`app/res/values/strings.xml`**

프로젝트의 app/res/values/strings.xml 파일에 아래 코드를 추가합니다.\
&#x20;추가한 코드 중 3번 라인 `serviceNumber`의 value를 올바른 값으로 변경해야 합니다.

{% tabs %}
{% tab title="string.xml" %}

```xml
<string-array name="dotAuthorizationKey">
    <item name="useMode">1</item>
    <item name="serviceNumber">xxxxx</item>     >>> 서비스 번호 확인 후 변경
    <item name="expireDate">14</item>
    <item name="isDebug">false</item>
    <item name="isInstallRetention">true</item>
    <item name="isFingerPrint">true</item>
    <item name="accessToken"></item>
</string-array>
```

{% endtab %}
{% endtabs %}

추가한 코드 중 `serviceNumber`의 value를 올바른 값으로 변경해야 합니다.&#x20;

[<mark style="color:blue;">와이즈트래커 대시보드</mark>](https://analytics.wisetracker.co.kr/)에 로그인하여 설정 > 서비스설정 메뉴에서 '<mark style="color:red;">`서비스번호`</mark>' 항목에 기재된 숫자를 확인 후 복사하여 serviceNumber 값을 변경 해 주세요.

<figure><img src="/files/u0EVIzLKa8twr6A3GIM4" alt=""><figcaption><p>서비스번호 확인</p></figcaption></figure>

### HTTP 통신 허용

{% hint style="warning" %}
이 내용은 Wisetracker 기본 SDK가 이미 적용된 경우에는 새로 적용할\
필요가 없습니다. 메시징 서비스만 이용하는 경우 참조해주세요.&#x20;
{% endhint %}

프로젝트의 Target API가 **API Level 28** 이상일 경우에 적용하는 설정입니다. 아래와 같이 HTTP 통신을 허용하는 두 가지 설정을 추가해주세요.\
작성되어 있는 코드에, 아래 한 줄 짜리 `networkSecurityConfig` 코드를 복사하여&#x20;

```
android:networkSecurityConfig="@xml/network_security_config"
```

\<application androidname = > 안에 붙여넣기 하면 아래 최종 코드와 같은 모양이 됩니다.

{% tabs %}
{% tab title="AndroidManifest.xml 최종코드" %}

```xml
<application androidname=".MainApplication"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:allowBackup="false"
    android:networkSecurityConfig="@xml/network_security_config" > <!-- API Level 28 이상일 경우 해당 라인 추가 --> 
    
```

{% endtab %}
{% endtabs %}

**app/res/xml/network\_security\_config.xml 설정**<br>

{% tabs %}
{% tab title="신규설정의 경우" %}

1. `network_security_config.xml` 파일을 생성합니다.
2. 로컬에서 개발하는 경우에는 아래와 같이 로컬 개발환경을 추가해야 metro server와 통신할 수 있습니다.

```xml
<domain includeSubdomains="true">localhost</domain>
```

3. 로컬 환경을 추가 한 후, xml 파일에 와이즈트래커 도메인을 추가 해 주세요.&#x20;

```xml
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">trk.analytics.wisetracker.co.kr</domain>
    </domain-config>
</network-security-config>
```

4. trk.analytics.wisetracker.co.kr :arrow\_forward: 도메인을 추가 해 주시면 와이즈트래커 SDK 통신이 가능해집니다.&#x20;
   {% endtab %}

{% tab title="기존에 설정되어있는 경우" %}
기존 network\_security\_config.xml 설정이 되어 있으셨다면,

```xml
<domain includeSubdomains="true">trk.analytics.wisetracker.co.kr</domain>
```

와이즈트래커 도메인을 '추가' 해주시면 와이즈트래커 SDK 통신이 가능합니다.
{% endtab %}
{% endtabs %}

### 푸시알림 권한 설정 (AndroidManifest.xml)

```xml
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
```

"android.permission.POST\_NOTIFICATIONS" 권한을 추가합니다. 이 권한 설정은 \<application> 태그 위에서 선언합니다.

```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="XXX">

    <!-- Wisetracker SDK for Push -->
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    ...
    
    <application
        android:name="ZZZ"
        ...>
```

### 초기화

Application을 상속받는 클래스가 아닌 `Activity`를 상속받는 기본 화면의 `onCreate()` 함수에 적용해 주세요. 여기서 말하는 기본 화면은 <mark style="color:red;">`AndroidManifest.xml`</mark> 파일에 선언된 Activity 중, `"`<mark style="color:red;">`android.intent.action.MAIN`</mark>`"` 과 `"`<mark style="color:red;">`android.intent.category.LAUNCHER`</mark>`"`  Intent-Filter 가 적용된 Activity를 의미합니다.&#x20;

Application을 상속받는 클래스가 아닌 `Activity`를 상속받는 기본 화면의 `onCreate()` 메쏘드에 적용해 주세요

{% tabs %}
{% tab title="Java" %}

```java
import com.sdk.wisetracker.new_dot.open.DOT;

public class MainActivity extends Activity {
  ...
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);    
    ...
    ...
    // SDK 호출
    DOT.initialization(this);
    ...
  }
  ...
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import com.sdk.wisetracker.new_dot.open.DOT

class MainActivity : AppCompatActivity() {
  ...
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    ...
    ...
    // SDK 호출
    DOT.initialization(this)
    ...
  }
}
```

{% endtab %}
{% endtabs %}

안드로이드 기초설정은 완료하셨습니다 🎉

다음으로 <mark style="color:blue;">**iOS 기초설정**</mark>을 위한 단계를 진행 해 주세요 👇🏻


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://document.wisetracker.co.kr/v2-developer/push/undefined/flutter/android.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
