2. AndroidManifest.xml 설정
APMS수행을 위한 Permission, Service, Receiver, Meta Data등을 설정합니다.
샘플 소스의 AndroidManifest.xml 참조
2.1 Permission 추가
<!-- push -->
<permission android:name="$(project_package).permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="$(project_package).permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<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" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- network -->
<!-- storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- storage -->
<!-- state -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- state -->
<manifest>
태그내에 추가합니다.
$(project_package)
는 manifest태그의 package를 의미합니다.
$(project_package)
적용 예제 (Package Name이 "com.humuson.app"일 경우)
<!-- push -->
<permission android:name="com.humuson.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.humuson.app.permission.C2D_MESSAGE" />
...
2.2 GCM receiver 추가
<!-- apms GCM Receiver -->
<receiver
android:name="com.apms.sdk.push.PushReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="$(project_package)" />
</intent-filter>
</receiver>
<application>
태그내에 추가합니다.
$(project_package)
는 manifest태그의 package를 의미합니다.
$(project_package)
적용 예제 (Package Name이 "com.humuson.app"일 경우)
<receiver
android:name="com.apms.sdk.push.PushReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.humuson.app" />
</intent-filter>
</receiver>
그리고 Google Service를 사용하기 위해서 다음과 같이 추가 해주셔야 합니다.
res폴더에 values에 version.xml 파일을 추가한뒤 아래 코드를 추가해주셔야 합니다.
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
2.3 PushPopupActivity 추가
<!-- apms push popup activity -->
<activity
android:name="${push_popup_activity}"
android:theme="@style/push_popup_theme"
android:excludeFromRecents="true"
android:exported="false"
android:screenOrientation="portrait"
android:configChanges="orientation" />
<application>
태그내에 추가합니다.
${push_popup_activity}
는 Push수신 시 출력될 Popup Activity의 className을 의미합니다.
- APMS에서 제공되는 기본 PushPopupActivity를 쓰고자 한다면, "com.apms.sdk.push.PushPopupActivity"를 셋팅하시면 됩니다.
- Custom PushPopupActivity를 쓰고자 한다면, 개발하신 className을
${push_popup_activity}
에 셋팅하시고, apms.properties의 push_popup_activity
의 값과 일치시켜 주시면 됩니다.
Custom PushPopupActivity 적용 예제 (PushPopupAcitivity className이 "com.custom.push.CusomPushPopupActivity"일 경우)
<!-- apms push popup activity -->
<activity
android:name="com.custom.push.CusomPushPopupActivity"
android:theme="@style/push_popup_theme"
android:excludeFromRecents="true"
android:exported="false"
android:screenOrientation="portrait"
android:configChanges="orientation" />
push_popup_activity=com.custom.push.CusomPushPopupActivity
2.4 PushNotiReceiver 추가
<!-- apms push clickNotiReceiver -->
<receiver android:name="${noti_receiver_class}" >
<intent-filter>
<action android:name="${noti_receiver}" />
</intent-filter>
</receiver>
<application>
태그내에 추가합니다.
${noti_receiver_class}
는 Push수신 시 출력되는 상단의 Notification을 터치 했을 때, 수행될 Receiver의 className을 의미합니다.
${noti_receiver}
는 Push수신 시 출력되는 상단의 Notification을 터치 했을 때, broadcasting할 intent action을 의미합니다.
- apms.properties 중
noti_receiver
항목에 noti receiver(intent action)를 일치시켜 주셔야 합니다.
NotiReceiver 적용 예제 (NotiReceiverClass className이 "com.custom.push.CustomNotiReceiverClass"이고, notiReceiver intent action이 "com.custom.push.notifiaction"일 경우)
<!-- apms push clickNotiReceiver -->
<receiver android:name="com.custom.push.CustomNotiReceiverClass" >
<intent-filter>
<action android:name="com.custom.push.notifiaction" />
</intent-filter>
</receiver>
noti_receiver=com.custom.push.notifiaction
2.5 Private Server service 및 receiver 추가
<!-- APMS Private RestartReceiver -->
<receiver android:name="com.apms.sdk.push.mqtt.RestartReceiver">
<intent-filter>
<action android:name="ACTION_MQTT_PING" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.ACTION_PACKAGE_RESTARTED" />
</intent-filter>
</receiver>
<!-- APMS Private connectionChangeReceiver -->
<receiver android:name="com.apms.sdk.push.mqtt.ConnectionChangeReceiver" android:label="NetworkConnection">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
<!-- Private PUSH Service -->
<service
android:name="com.apms.sdk.push.mqtt.MQTTService"
android:enabled="true"
android:exported="true"
android:label="PushService"
android:process="${process_name}" />
<!-- Private PUSH Receiver -->
<receiver android:name="com.apms.sdk.push.PushReceiver" >
<intent-filter>
<action android:name="org.mosquitto.android.mqtt.MSGRECVD" />
<category android:name="${project_package}" />
</intent-filter>
</receiver>
<application>
태그내에 추가합니다.
${process_name}
는 Android Process Name을 의미합니다.
${process_name}
적용 예제 (Process Name이 "com.apms.sdk.HumusonpushService"일 경우)
<!-- Private PUSH Service -->
<service
android:name="com.apms.sdk.push.mqtt.MQTTService"
android:enabled="true"
android:exported="true"
android:label="PushService"
android:process="com.apms.sdk.HumusonpushService" />
${project_package}
는 manifest태그의 package를 의미합니다.
${project_package}
적용 예제 (Package Name이 "com.humuson.app"일 경우)
<!-- Private PUSH Receiver -->
<receiver android:name="com.apms.sdk.push.PushReceiver" >
<intent-filter>
<action android:name="org.mosquitto.android.mqtt.MSGRECVD" />
<category android:name="com.humuson.app" />
</intent-filter>
</receiver>
2.6 Data Sender service 및 receiver 추가
<!-- APMS Data Sender Service -->
<service
android:name="com.apms.sdk.service.DataSenderService"
android:enabled="true"
android:exported="true"
android:label="SenderService"
android:process="${process_name}" />
<!-- APMS Data Sender receiver -->
<receiver android:name="com.apms.sdk.service.SenderSeviceReceiver" >
<intent-filter>
<action android:name="SENDER.START" />
<action android:name="SENDER.STOP" />
</intent-filter>
</receiver>
${process_name}
는 Android Process Name을 의미합니다.
${process_name}
적용 예제 (Process Name이 "com.apms.sdk.DataSenderService"일 경우)
<!-- APMS Data Sender Service -->
<service
android:name="com.apms.sdk.service.DataSenderService"
android:enabled="true"
android:exported="true"
android:label="SenderService"
android:process="com.apms.sdk.DataSenderService" />
2.7 Notification 설정 값 추가
<meta-data android:name="APMS_NOTI_CONTENT" android:value="${noti_content}" />
- Image 포함한 Notification 노출시 Image가 안보일시 보이는 메세지 내용입니다.
- 위의 값을 설정해주면 위의 내용이 보이게 됩니다.
${noti_content}
적용 예제 (value가 "두손가락을 이용해 아래로 당겨주세요."일 경우)
<meta-data android:name="APMS_NOTI_CONTENT" android:value="두손가락을 이용해 아래로 당겨주세요." />
- Resource/value/string.xml에 'finger_event'로 등록된 값을 사용할 경우
<meta-data android:name="APMS_NOTI_CONTENT" android:value="@string/finger_event" />
2.8 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}" />
${icon_file_name}
는 Notification Icon에 등록될 Icon File Name을 넣으시면 됩니다.
- Android 5.0부터는 App Icon과 Notification Bar 표시되는 Icon이 달라야 합니다.
2.9 Push Alram Sound 설정 값 추가
<meta-data android:name="APMS_SET_NOTI_SOUND" android:resource="@raw/${ring_file_name}"/>
${ring_file_name}
Resource/Raw/ 저장한 벨소리 파일 네임을 넣으시면 됩니다.
- 디바이스 디폴트 알람소리를 이용하실려면 빼셔도 됩니다.
3. Style 추가
- style.xml에 push popup의 투명배경을 위한 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>
4. apms.properties 파일 설정
- APMS 수행을 위한 서버URL 셋팅 및 설정값을 저장 합니다.
# APMS App Key & API Server Url Setting
# GCM발송을 위한 앱의 projectId로 GCM의 pushToken을 가져오는데 사용됩니다.
gcm_project_id=${Google_Project_Number}
# APMS Admin Web에서 앱 생성 시 발급되는 key입니다.
app_key=${App_key}
# APMS 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}
# private server와의 keep alive time을 의미합니다. 단위는 초(second)입니다.
# (KeepAlive Total Time : Keep alive time + Ramdom Time(2~4min))
mqtt_server_keepalive=${mqtt_keepalive}
# DEBUG MODE
# Logcat 관련 설정 입니다.
debug_tag=APMS
debug_flag=Y
# Service에 대한 로그를 파일로 저장 유무를 설정합니다.
debug_log_falg=Y
# APMS SETTING
# Push 수신시 화면 On/Off를 의미 합니다.
screen_wakeup_flag=Y
# Push 수신시 화면에 보여지는 시간을 의미 합니다. (단위 : ms)
push_popup_showing_time=9999999
# Push 노출을 앱 사용중에만 노출 할 것인지(디폴트값) 아니면
# 다른앱을 사용중에만 빼고 노출 할 것인지 설정값입니다. (default = N)
push_popup_showing_flag=N
# Push수신 시 출력되는 상단의 Notification을 터치 했을 때, broadcasting할 intent action을 의미합니다.
noti_receiver=${noti_receiver}
# Push수신 시 출력될 Popup Activity의 className을 의미합니다.
# (Default Class : "com.apms.sdk.push.PushPopupActivity")
push_popup_activity=${push_popup_activity}
- GCM발송을 위한 Project ID 가져오는 방법
- 구글 광고 정책에 의해서 앱이 실행중에만 팝업이 노출되게 되어있습니다.
- 하지만,
push_popup_showing_flag
를 Y
로 두시면 예전과 동일하게 사용가능 합니다.
5. Notification Bar Touch에 대한 BroadcastReceiver 작성
Push수신 시 출력되는 Notification Bar의 터치에 대한 특정 로직을 삽입하고자 할 때, 작성하는 class 입니다.
NotiReceiver 셋팅은 pushNotiReceiver 추가
항목을 참조 하시기 바랍니다.
5.1 CustomNotiReceiverClass
BroadcaseReceiver를 extends받아서 작성 합니다.
intent에서 Data를 가져오는 방법은 Push Data
항목을 참조 하시기 바랍니다.
package com.custom.push;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class CustomNotiReceiverClass extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// notification 터치 시에 “push notiMsg:${notiMsg}” 라는 텍스트를 Toast로 출력합니다.
Toast.makeText(contetx, "push notiMsg:" + intent.getStringExtra(APMS.KEY_NOTI_MSG),
Toast.LENGTH_SHORT).show();
}
}
5.2. Push Data
onReceivePushListener의 intent에서 참조 할 수 있으며, 다음과 같이 데이터를 가져 올 수 있습니다.
intent.getStringExtra(APMS.KEY_MSG_ID) // "i" - 메세지 ID
intent.getStringExtra(APMS.KEY_NOTI_TITLE) // "notiTitle" - notification에 출력될 타이틀
intent.getStringExtra(APMS.KEY_NOTI_MSG) // "notiMsg" - notification에 출력될 메시지 내용
intent.getStringExtra(APMS.KEY_NOTI_IMG) // "notiImg" - notification에 출력될 이미지 URL
intent.getStringExtra(APMS.KEY_MSG) // "message" - (리치) 푸시 내용
intent.getStringExtra(APMS.KEY_SOUND) // "sound" - 푸시 수신 시 출력될 사운드
intent.getStringExtra(APMS.KEY_MSG_TYPE) // "t" - 메시지 타입 : H – html, T – Text, L – Link
intent.getStringExtra(APMS.KEY_POPUP_FLAG) // Popup 창을 제어하는 Flag
intent.getStringExtra(APMS.KEY_DATA) // "d" - 추가 데이터
- PushMsg Bean를 이용해서 가져오는 예제
PushMsg pushMsg = new PushMsg(intent.getExtras());
pushMsg.msgId // 메세지 ID
pushMsg.notiTitle // notification에 출력될 타이틀
pushMsg.notiMsg // notification에 출력될 메시지 내용
pushMsg.notiImg // notification에 출력될 이미지 URL
pushMsg.message // (리치) 푸시 내용
pushMsg.sound // 푸시 수신 시 출력될 사운드
pushMsg.msgType // 메시지 타입 : H – html, T – Text, L – Link
pushMsg.popupFlag // Popup 창을 뛰울지 말지 결정 Flag (Y & N)
pushMsg.data // 추가 데이터