Android SDK Manual
Android SDK 3.5.0 변경 사항
※ GCMConstants 클래스 삭제.
GCMConstants 의 getToken, getDeviceIdx 메소드는 FingerPushManager 로 이관되었습니다.
※ AndroidX 적용되었습니다. gradle.properties 파일에 아래와 같이 추가합니다.
android.useAndroidX=true
android.enableJetifier=true
※ setPushAlive() API 가 deprecated 되었습니다. setPushEnable() API 를 사용해주세요.
※ GCMConstants 클래스 삭제.
GCMConstants 의 getToken, getDeviceIdx 메소드는 FingerPushManager 로 이관되었습니다.
※ AndroidX 적용되었습니다. gradle.properties 파일에 아래와 같이 추가합니다.
android.useAndroidX=true
android.enableJetifier=true
※ setPushAlive() API 가 deprecated 되었습니다. setPushEnable() API 를 사용해주세요.
1. 핑거푸시 관리자 사이트 APP 생성
2. FCM APP 생성
3. 핑거푸시 관리자 사이트에 APP 키 등록하기
5. Properties 키 등록하기
3. FingerPush.properties 파일에 핑거푸시 App key, App Secret, FCM 발신자(Sender) ID 를 입력합니다.
APP_KEY = 핑거푸시 App key APP_SECRET = 핑거푸시 App Secret GOOGLE_PROJECT_ID = FCM 발신자(Sender) ID
<project>/<app-module>/src/main/assets/FingerPush.properties
6.Gradle 설정
1. 프로젝트 build.gradle(Top-level build.gradle)에 ‘classpath ‘com.google.gms:google-services:3.2.0’ 을 추가합니다.
buildscript { repositories { jcenter() } dependencies { ... classpath 'com.google.gms:google-services:3.2.0' } }
<project>/build.gradle
2. 앱 수준 build.gradle(Module-level build.gradle) 최하단에 apply plugin: ‘com.google.gms.google-services’ 을(를) 추가합니다.
// add this at the bottom apply plugin: 'com.google.gms.google-services'
<project>/<app-module>/build.gradle
3. dependencies 에 compile ‘compile ‘com.google.firebase:firebase-messaging:18.0.0’, compile ‘com.google.firebase:firebase-core:16.0.9’ 을(를) 추가합니다.
dependencies { compile 'com.google.firebase:firebase-messaging:18.0.0' compile 'com.google.firebase:firebase-core:16.0.9' }
<project>/<app-module>/build.gradle
7. AAR 추가하기
5. import한 fingerpush.aar 파일을 선택합니다.
6. 정상적으로 fingerpush.aar 파일이 추가됐다면 module-level build.gradle 에 행이 추가됩니다.
... dependencies { ... compile project(':fingerpush') }
<project>/<app-module>/build.gradle
8. AndroidX Migration
1. gradle.properties 파일에 아래와 같이 추가합니다.
android.useAndroidX=true android.enableJetifier=true
gradle.properties
9. 디바이스 등록
1. MainActivity.java 에서 ‘FingerPushManager.getInstance(Context).setDevice(ObjectListener)’ 메소드를 호출합니다.
@Override protected void onCreate(Bundle savedInstanceState) { ... FingerPushManager.getInstance(Context).setDevice(new NetworkUtility.ObjectListener() { @Override public void onComplete(String code, String message, JSONObject jsonObject) { // code 200, 201 이 반환된 경우 정상적으로 디바이스가 등록된 것입니다. } @Override public void onError(String code, String message) { // 코드 504 가 반환된 경우 이미 디바이스가 등록된 상태입니다. } }); }
MainActivty.java
※ 단말기 토큰은 생성, 파기, 갱신 등의 생명주기가 있기 때문에 때문에
setDevice() 함수를 앱 실행시 항시 호출해야 합니다.
10. IntentService 클래스 생성
2. 생성한 IntentService.java 클래스 파일에서 ‘FingerPushFcmListener’을 상속받습니다.
상속 받은 뒤 ‘onMessage(Context context, Bundle data)’ 를 override 합니다.
상속 받은 뒤 ‘onMessage(Context context, Bundle data)’ 를 override 합니다.
public class IntentService extends FingerPushFcmListener { @Override public void onMessage(Context context, Bundle data) { createNotificationChannel(data); } }
* 기본 Notification 생성 방법
※ Caution
Target Android 8.0 (API level 26) 이상은 ‘Channel’ 을 생성해야 Notification 이 노출됩니다.
Channel은 최초 생성 후 사용자가 제어권을 가져가게 됩니다. Channel Name 과 Channel Description 은 변경 가능합니다.
Channel 에 대한 상세 내용은 [페이지 이동] 을 참조바랍니다.
private void createNotificationChannel(Bundle data) { NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel mChannel = new NotificationChannel("Channel ID", "Channel Name", NotificationManager.IMPORTANCE_HIGH); mChannel.setDescription(null); mNotificationManager.createNotificationChannel(mChannel); } Intent intent = new Intent(IntentService.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(IntentService.this, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(data.getString("data.message")) .setContentText("Hello World!"); mBuilder.setContentIntent(pi); mNotificationManager.notify((int) System.currentTimeMillis(), mBuilder.build()); }
IntentService.java
* FingerNotification 생성 방법
FingerNotification은 기존 Notification 보다 좀 더 편하게 생성할 수 있게 핑거푸시에서 제공하는 클래스입니다.
private void createNotificationChannel(Bundle data) { Intent intent = new Intent(IntentService.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(IntentService.this, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_CANCEL_CURRENT); FingerNotification fingerNotification = new FingerNotification(this); fingerNotification.setNotificationIdentifier((int) System.currentTimeMillis()); fingerNotification.setIcon(R.drawable.m_ic_launcher); // Notification small icon fingerNotification.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)); fingerNotification.setVibrate(new long[]{0, 500, 600, 1000}); fingerNotification.setLights(Color.parseColor("#ffff00ff"), 500, 500); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { fingerNotification.setColor(Color.rgb(0, 114, 162)); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { fingerNotification.createChannel("channel_id", "channel_name"); } fingerNotification.showNotification(data, pi); }
IntentService.java
3. 디바이스에서 푸시 수신 데이터(Payload)는 Bundle 타입으로 전달 받을 수 있으며, Bundle 데이터는 아래와 같습니다.
data.msgTag : 메세지 번호 data.code : CD:1;IM:0;PT:DEFT data.time : 보낸시간 data.appTitle : 핑거푸시 앱이름 data.badge : 뱃지 data.sound : 사운드 data.title : 메세지 제목 data.message : 메세지내용 data.weblink : 웹링크 url data.labelCode : 라벨코드 data.img : 이미지여부 data.imgUrl : 이미지url data.cd1 : 커스텀 데이터 data.cd2 : 커스텀 데이터 data.cd3 : 커스텀 데이터
onMessage Bundle 데이터
4. MessageID, MessageLabel, PushMode 가져오는 방법
String messageId = FingerPushManager.getMessageId(Bundle bundle); String messageLabel = FingerPushManager.getMessageLabel(Bundle bundle); String pushMode = FingerPushManager.getPushMode(Bundle bundle);
11. AndroidManifest 설정
1. allowBackup 값을 false 로 설정합니다.
<application android:allowBackup="false" android:icon="@mipmap/ic_launcher" android:label="@string/app_name"> ... </application>
AndroidManifest.xml
2. 9번에서 생성한 IntentService 클래스를 AndroidManifest.xml에 추가합니다.
<application> ... <service android:name=".IntentService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> </application>
AndroidManifest.xml
12. 저장소 권한 설정
1. 디바이스 관리를 위해 저장소 권한을 사용하는 것을 권장합니다.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE_STORAGE); } else { setDeivce(); } } else { setDeivce(); }
2. 저장소 권한 여부를 체크한 후, 허용 또는 거부와 무관하게 setDevice() 를 호출합니다.
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { switch (requestCode) { case REQUEST_CODE_STORAGE: setDevice(); break; } }
3. Target SDK 가 API 29 이상이면서, 외부 저장소를 사용하려면 requestLegacyExternalStorage 값을 true 로 변경합니다.
<application android:requestLegacyExternalStorage="true"> ... </application>
AndroidManifest.xml
13. ProGuard 설정
1. ProGuard 를 사용하는 경우 다음 규칙을 추가합니다.
# For FingerPush SDK -dontwarn com.fingerpush.**
API 연동 결과 코드
코드 | 내용 | 비고 |
---|---|---|
200 | 정상처리 | |
403 | App_key, secret 오류, 권한없음 | |
404 | 조회 대상 없음, 조회 결과 없음 | |
500 | 처리 중 에러 | |
503 | 필수 값 없음 | |
504 | 이미 등록된 토큰 | 디바이스 등록에서만 사용 |