APMS SDK User Guide

첨부파일

​ ​ ​ ​ ​ ​ ​ ​
파일명설명
SDK_Android_APMS_xxx.jarAPMS 라이브러리
apms.propretiesAPMS 설정 파일
org.eclipse.paho.client.mqttv3-1.2.0(mlog).jar Private 서비스를 사용하기 위해 사용되는 MQTT 라이브러리
apms-sdk.jsClick을 잡는 스크립트 파일

1. 라이브러리 적용 방법

1. Android Studio에서 보기 형식을 Project로 변경하여 주시기 바랍니다.

2. libs 폴더에 SDK_Android_APMS_xxx.jar 파일과 org.eclipse.paho.client.mqttv3-1.2.0(mlog).jar 파일을 넣어 주시기 바랍니다.

3. 해당 프로젝트의 app 내부에 있는 build.gradle의 dependencies에 다음 사항을 추가하여 주시기 바랍니다.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.firebase:firebase-core:16.0.5'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
}

4. 해당 프로젝트의 app 내부에 있는 build.gradle의 android에 buildToolsVersion을 기입하여 주시기 바랍니다.

android {
    compileSdkVersion 26
    buildToolsVersion '28.0.3'
}

5. 해당 프로젝트의 app 내부에 있는 build.gradle의 dependencies 밑에 다음 항목을 추가하여 주시기 바랍니다.

dependencies {
...
}
apply plugin: 'com.google.gms.google-services'

6. 해당 프로젝트의 가장 바깥쪽에 위치한 build.gradle 파일에 다음 사항들을 추가하여 주시기 바랍니다.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.1.0'
    }
}
allprojects {
    repositories {
        jcenter()
        google()
    }
}

7. FCM을 사용하기위해 Firebase Console에서 프로젝트 등록시 다운로드 받았던 google-services.json 파일을 app 폴더 아래로 복사를 합니다.

8. MQTT 라이브러리 파일을 프로젝트 libs 폴더에 복사 붙여넣기 합니다.

9. 통신 라이브러리 파일을 프로젝트에 import 합니다.

dependencies {
    implementation 'com.android.volley:volley:1.1.1'
    ...
}

10. 오른쪽 상단에 뜨는 Sync Now를 클릭하여서 Build를 완료합니다.

11. 해당 프로젝트의 app / src / main 폴더에 assets 디렉토리를 생성합니다.

12. assets 디렉토리 내에 첨부파일에 있었던 apms.propertiesapms-sdk.js 파일을 넣어 줍니다.

13. 어플리케이션의 최초 표시 화면의 Activity에 SDK의 초기화 작업을 진행합니다.

APMS sdk = APMS.getInstance(activity.getApplicationContext());
sdk.setPopupNoti(true);
sdk.setRingMode(true);
sdk.setVibeMode(true);
sdk.setIsPopupActivity(true);
sdk.setNotiOrPopup(false);
...

주의사항

2. AndroidManifest.xml 설정

2.1 Permission 추가

<!-- push --> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.VIBRATE" />
<!-- push -->

<!-- network -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- network -->

2.2 FCM receiver 추가

<receiver
    android:name="com.apms.sdk.push.PushReceiver"
    android:exported="true" >
    <intent-filter>
        <action android:name="com.google.android.fcm.intent.RECEIVE" />
        <action android:name="org.mosquitto.android.mqtt.MSGRECVD" />
    </intent-filter>
</receiver>

<service
    android:name="com.apms.sdk.push.FCMPushService"
    android:exported="false" >
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

2.3 PushPopupActivity 추가

<!-- apms push popup activity -->
<activity
    android:name="${push_popup_activity}"
    android:theme="@style/push_popup_theme"
    android:excludeFromRecents="true"
    android:taskAffinity=".PushPopupActivity"
    android:screenOrientation="portrait"
    android:configChanges="orientation" />

2.4 PushNotiReceiver 추가

<!-- apms push clickNotiReceiver -->
<receiver android:name="${noti_receiver_class}" >
    <intent-filter>
        <action android:name="${noti_receiver}" />
    </intent-filter>
</receiver>

2.5 Private Server service 및 receiver 추가

<!-- APMS Private RestartReceiver -->
<receiver android:name="com.apms.sdk.push.mqtt.RestartReceiver">
    <intent-filter>
        <action android:name="MQTT.START"/>
       <action android:name="MQTT.RESTART"/>
       <action android:name="MQTT.FORCE_START"/>
       <action android:name="android.intent.action.BOOT_COMPLETED"/>    </intent-filter>
</receiver>
    
<!-- Private PUSH Service -->
<service
    android:name="com.apms.sdk.push.mqtt.MQTTService"
    android:enabled="true"
    android:label="PushService"
    android:process="${process_name}" />

2.6 Notification 설정 값 추가

<meta-data android:name="APMS_NOTI_CONTENT" android:value="${noti_content}" />

2.7 Notification Icon 설정 값 추가

<meta-data android:name="APMS_SET_ICON" android:resource="@drawable/${icon_file_name}" />
<meta-data android:name="APMS_SET_LARGE_ICON" android:resource="@drawable/${icon_file_name}" />

2.8 Notification Icon Backgroud Color 지정.

<meta-data android:name="APMS_NOTI_BACK" android:value="\#000000" />

2.9 Push Alram Sound 설정 값 추가

<meta-data android:name="APMS_SET_NOTI_SOUND" android:resource="@raw/${ring_file_name}"/>

2.10 Android 9.0 대응 코드 추가

<uses-library android:name="org.apache.http.legacy" android:required="false"/>

3. Java Class 추가

APMS mApms = APMS.getInstance(mCon);
mApms.setPopupSetting(false, mCon.getString(R.string.app_name)); // Custom Popup을 사용여부
mApms.setPopupNoti(true); // 팝업창을 사용 여부
mApms.setRingMode(true); // 알림을 사용 여부
mApms.setVibeMode(true); // 진동 사용 여부
mApms.setIsPopupActivity(false); // 다른 앱 실행이 팝업창을 사용 여부
mApms.setNotiOrPopup(false); // Text Popup을 Toast로 사용 여부

4. Style 추가

<!-- push popup theme -->
<style name="push_popup_theme" parent="android:Theme.Light">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

5. apms.properties 파일 설정

# App Key & API Server Url Setting
# FCM발송을 위한 앱의 projectId로 FCM의 pushToken을 가져오는데 사용됩니다.
gcm_project_id=${Google_Project_Number}

# Admin Web에서 앱 생성 시 발급되는 key입니다.
app_key=${App_key}

# Msg-Api Url을 의미합니다.
api_server_url=${Msg_Api_Url}

# Private Server Setting
# mqtt의 사용여부를 의미합니다. ("Y":사용, "N":사용하지 않음)
mqtt_flag=${mqtt_flag}

# private server와 연동 시 필요한 server url을 의미합니다. 
# 반드시 다음과 같이 protocol, url, port를 전부 입력해주셔야 합니다. (사용하지 않을시에는 공백처리)
mqtt_server_url_ssl=${mqtt_ssl_url}
mqtt_server_url_tcp=${mqtt_tcp_url}

# DEBUG MODE
# Logcat 관련 설정 입니다.
debug_tag=APMS
debug_flag=Y

# Service에 대한 로그를 파일로 저장 유무를 설정합니다.
debug_log_falg=Y

# APMS SETTING
# Push 수신시 화면 On/Off를 의미 합니다.
screen_wakeup_flag=Y

# Text Notification 생성시 BigText Mode 사용 여부 (사용 : Y , 미사용 : N)
big_text_mode=Y

# Push 수신시 화면에 보여지는 시간을 의미 합니다. (단위 : ms)
push_popup_showing_time=9999999

# Push 노출을 앱 사용중에만 노출 할 것인지(디폴트값) 아니면
# 다른앱을 사용중에만 빼고 노출 할 것인지 설정값입니다. (default = N)
push_popup_showing_flag=N

# Push수신 시 출력될 Popup Activity의 className을 의미합니다.
# (Default Class : "com.apms.sdk.push.PushPopupActivity")
push_popup_activity=${push_popup_activity}

## 푸시 "수신"시 동작하는 Class이름 입니다.
## CustomPushReceiver가 필요할 경우 사용됩니다.
## 직접 구현 하셔야하며 필요하지 않을 경우 작성하지 않으셔도 됩니다.
push_receiver_class=com.example.CustomPushReceiver

# Push수신 시 출력되는 상단의 Notification을 터치 했을 때, broadcasting할 intent action을 의미합니다.
noti_receiver=${noti_receiver}

## 푸시 수신시 표시되는 상단 알림 창을 "클릭"했을때 동작하는 Class이름 입니다
## App에서 따로 직접 구현해야 합니다
noti_receiver_class=com.example.PushNotiReceiver

## 앱 아이콘 오른쪽 상단에 표시되는 벳지의 표시 유무입니다 (Y는 표시, N은 미표시)
noti_o_badge=Y

## Android 7.0이상 부터 적용되는 알림 그룹화 기능입니다 (Y는 그룹화, N은 그룹화 비활성화)
noti_group_flag=Y

6. Notification Bar Touch에 대한 BroadcastReceiver 작성

6.1 CustomNotiReceiverClass

6.2. Push Data

6.3 푸시 수신시 AppLink값 추출 방법

7 삼성 스마트 절전 앱 대응 방안.

// Device 가 6.0 이상일 경우
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
    // 확인할 Permission 들을 추가할 ArrayList
    ArrayList<String> strArrPermission = new ArrayList<String>();
    // READ_PHONE_STATE 퍼미션이 존재 하지 않을 경우 퍼미션 추가 팝업을 띄위기 위해 ArrayList 에 추가
    int permissionCheck = ContextCompat.checkSelfPermission([context],      
                            Manifest.permission.READ_PHONE_STATE);
    // 만약 해당 퍼미션이 없을 경우 ArrayList에 확인할 퍼미션을 추가합니다.
    if (permissionCheck == PackageManager.PERMISSION_DENIED) {
        CLog.i("READ_PHONE_STATE PERMISSION_DENIED");
        strArrPermission.add(Manifest.permission.READ_PHONE_STATE);
        strArrPermission.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    // Permission 팝업을 띄위기 위한 String array 를 만들어 퍼미션 요청을 수행합니다.
    if (strArrPermission.size() > 0) {
        String[] strPermission = new String[strArrPermission.size()];
        for (int i=0; i<strArrPermission.size(); i++) {
            strPermission[i] = strArrPermission.get(i);
        }
        ActivityCompat.requestPermissions((Activity) this, strPermission, 0);
    }
}

9 Gradle 적용사항 정리

android {
   compileSdkVersion 26
   }
dependencies {
...
compile 'com.android.support:support-v4:26.1.0'
}
dependencies {
...
compile 'com.google.firebase:firebase-core:16.0.5'
compile 'com.google.firebase:firebase-messaging:17.3.4'
}
android {
    compileSdkVersion 26
    buildToolsVersion '28.0.3'
}
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.1.0'
    }
}
allprojects {
    repositories {
        jcenter()
        google()
    }
}