1. 라이브러리 추가하기

아래 방식 중 개발환경에 맞는 메뉴를 선택해서 적용해주세요.(메뉴 왼쪽의 ▶︎버튼을 누르면 메뉴가 펼쳐집니다.)

2. AndroidManifest.xml 에 설정 추가하기

AndroidManifest.xml에 유저해빗 웹사이트에서 앱을 생성한 후 발급받은 API 키를 등록해주세요.

⚠️ 적용할 프로젝트가 target SDK 28+일 경우, 안드로이드 9.0(Pie)정책에 의해 Apache HTTP 클라이언트 권한이 반드시 필요합니다.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="<http://schemas.android.com/apk/res/android>"
  package="io.userhabit.myapplication2.app" >

  <!--인터넷 권한 추가-->
  <uses-permission android:name="android.permission.INTERNET"/>
  <!--네트워크 상태 체크 권한 추가-->
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

  <application
			android:name=".YourApplication" //application 등록
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >

			<!-- targetSDK 28+ Apache Client Registration for UserhabitSDK-->
      <uses-library
           android:name="org.apache.http.legacy"
           android:required="false" />
      
      <!--해당하는 API KEY 발급 받기-->
      <meta-data android:name="userhabitApiKey" android:value="API KEY" />

      <!--유저해빗 서비스 등록하기-->
      <service android:name="io.userhabit.service.main.service.UserhabitService" />
  </application>
</manifest>

3. 소스 코드 추가하기

아래와 같이 지정된 Application 클래스 내부에 유저해빗 함수를 적용합니다. (API 9 지원 프로젝트에 아래 방법을 도입하면 API 14 이상 기기만 데이터를 수집합니다.)

public class YourApplication extends Application {
    public void onCreate() {
        super.onCreate(); 
        Userhabit.start(this);
  }
}

4. 프로가드 적용하기

프로가드를 사용하실 경우 아래와 같이 예외 처리 코드를 추가해주세요.

-dontwarn org.apache.http.**
-dontwarn android.support.**
-dontwarn android.webkit.WebViewClient
-keep class org.apache.** { *; }
-keep interface org.apache.http.** { *; }
-keepnames interface android.support.v4.** { *; }
-keepnames class android.support.v4.** { *; }
-keepnames class android.support.v7.** { *; }
-keepnames interface android.support.v7.** { *; }
-dontwarn org.apache.http.**
-dontwarn android.support.**
-dontwarn android.webkit.WebViewClient
-dontwarn androidx.**
-keep class org.apache.** { *; }
-keep interface org.apache.http.** { *; }
-keep class androidx.** { *; }
-keep interface androidx.** { *; }