Morpheus Push 는 스마트폰 OS에서 지원하는 PNS(Push Notification Server)를 기반으로 한 메세지 전송 플랫폼이다.
Android Client 에서는 UPMC WAS 에서 제공하는 Push API 를 각각 버전 규격에 맞춰 연동하여 원할하게 Push Service 를 운영하기 위한 라이브러리를 제공한다.
가. Message-AI의 서비스 그룹에서 확인한 서비스 그룹 아이디를 <project-id> </project-id>에 입력
나. 접속할 서버 정보를 <server> </server> 에 입력. 여기서는 https://upmc.message-ai.net 고정
다. Firebase Console 에서 획득한 발신자 ID (Sender ID) 를 <fcm-sender-id> </fcm-sender-id> 에 입력한다.
라. log 와 file log 는 필요시 수정한다.
Manifest.xml 예시
<?xml version="1.0" encoding="UTF-8"?><settings><push><!-- key 교환 방식 암호화 : 라이선스 발급시 요청 (hexa코드 16자리) --><security-indexes>0x35b0x6a30x7590x77d0x3010x10a0x6440x78d0x3740x2f60x1b50x220x3100x1380x5950x547</security-indexes><receiver><project-id>testtesttesttesttesttesttesttest</project-id><log>y</log><file-log>n</file-log><!-- UPMC 서버 버전 5.0--><version>5.0</version><!-- UPMC 서버 URL--><server>https://upmc.message-ai.net</server><!-- 타임아웃 시간 --><timeout>20000</timeout><fcm-sender-id>1234123412341234</fcm-sender-id><android-push-type>FCM</android-push-type><!-- 브로드캐스트 리시버에서 퍼미션 사용 여부를 설정 (Y/N) --><use-permission>Y</use-permission></receiver></push></settings>
해당 샘플에서는 간단하게 푸시유저 등록을 하는 테스트를 하기 위한 코드를 작성하여 사용하였다.
privatevoidpushUserAdd(){JSONObjectuserInfo=PushManager.getInstance().getUserInfo(getApplicationContext());Stringcuid=userInfo.optString("CLIENT_UID");Stringname=userInfo.optString("CLIENT_NAME");if(TextUtils.isEmpty(cuid)){// 구분 가능한 IDcuid=PushUtils.getDeviceId(getApplicationContext());}if(TextUtils.isEmpty(name)){// 이름name="TEST";}// 유저 등록PushManager.getInstance().registerServiceAndUser(getApplicationContext(),cuid,name);}
MessageArrivedReceiver 는 BroadcastReceiver 를 상속받아 생성한다.
MessageArrivedReceiver 예시
importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importcom.uracle.push.test.helper.PushNotifyHelper;importorg.json.JSONObject;importm.client.push.library.common.Logger;importm.client.push.library.common.PushConstants;publicclassMessageArrivedReceiverextendsBroadcastReceiver{@OverridepublicvoidonReceive(Contextcontext,Intentintent){if(intent.getAction().equals(context.getPackageName()+PushConstants.ACTION_GCM_MESSAGE_ARRIVED)){try{// 수신된 payload data 는 아래 3가지 방식으로 획득 할 수 있다.Stringdata=intent.getExtras().getString(PushConstants.KEY_JSON);StringrawData=intent.getExtras().getString(PushConstants.KEY_ORIGINAL_PAYLOAD_STRING);byte[]rawDataBytes=intent.getExtras().getByteArray(PushConstants.KEY_ORIGINAL_PAYLOAD_BYTES);Logger.i(newJSONObject(data).toString(2));Logger.i("received raw data : "+rawData);Logger.i("received bytes data : "+newString(rawDataBytes,"utf-8"));// 노티피케이션 생성PushNotifyHelper.showNotification(context,newJSONObject(data));}catch(Exceptione){e.printStackTrace();}}}}
가. service 등록 : FCMIntentService
나. receiver 등록 : MessageArrivedReceiver, FcmActionReceiver
다. permission 등록 : ${applicationId}.permission.MPUSH_PERMISSION
라. uses-permission 등록 : ${applicationId}.permission.MPUSH_PERMISSION, android.permission.WAKE_LOCK
AndroidManifest.xml 예시
<?xml version="1.0" encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"package="com.push.cloud"><applicationandroid:requestLegacyExternalStorage="true"android:allowBackup="false"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/AppTheme"android:usesCleartextTraffic="true"><activityandroid:name=".MainActivity"android:label="@string/app_name"android:theme="@style/AppTheme.NoActionBar"><intent-filter><actionandroid:name="android.intent.action.MAIN"/><categoryandroid:name="android.intent.category.LAUNCHER"/></intent-filter></activity><!-- =================== PUSH SERVICE SETTINGS START============= --><!-- FirebaseMessagingService 를 상속받아 구현 됨 --><serviceandroid:name="m.client.push.library.service.FCMIntentService"android:exported="false"tools:ignore="Instantiatable"><intent-filter><actionandroid:name="com.google.firebase.MESSAGING_EVENT"/></intent-filter></service><!-- 푸시 payload data 수신 class --><receiverandroid:name=".receiver.MessageArrivedReceiver"><intent-filter><actionandroid:name="${applicationId}.GCM_MESSAGE_ARRIVED"/></intent-filter></receiver><!-- UPMC 서비스 등록 / 해제 등을 위한 class --><receiverandroid:name="m.client.push.library.receiver.FcmActionReceiver"><intent-filter><actionandroid:name="${applicationId}.ACTION_GCM"/></intent-filter></receiver></application><!-- 푸시 BroadCast 수신 권한 용 Permission --><permissionandroid:name="${applicationId}.permission.MPUSH_PERMISSION"android:protectionLevel="signature"/><uses-permissionandroid:name="${applicationId}.permission.MPUSH_PERMISSION"/><!-- 푸시 수신 후, screen on 을 위한 permission--><uses-permissionandroid:name="android.permission.WAKE_LOCK"/><uses-permissionandroid:name="android.permission.INTERNET"/><uses-permissionandroid:name="android.permission.VIBRATE"/><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/><!-- =================== PUSH SERVICE SETTINGS END ============= --></manifest>