Tích hợp AdBrix Growth Action [Android - Kotlin]
Theo dõi
Thông tin cần biết
Để sử dụng Growth Action, cần cài đặt common adbrix SDK và Firebase Cloud Messaging SDK (bên dưới sẽ gọi là FCM).
Common adbrix SDK cần được hoàn thành tích hợp trước khi tiếp tục bước này.
- Common adbrix SDK - Tích hợp AdBrix Android SDK [Kotlin]
- FCM SDK - Cài đặt Firebase Messaging SDK cho Android
[[인용:안내:보통]] Để sử dụng Growth Action
_ Growth Action là giải pháp cung cấp gửi Push Notification tự động theo Scenario và targeting audience.[Chi tiết]
_ Growth Action là premium add-on mở rộng, để sử dụng tính năng này cần sử dụng gói Paid Pricing Plan. [Service Request]
Cấu hình Growth Action cơ bản
Đăng kí Firebase Server Key, Sender ID
Đầu tiên cần đăng kí Firebase Server Key / Sender ID với AdBrix.
a. Vào Firebase Console để lấy Server Key / Sender ID.
b. Vào adbrix console, Growth Action > Settings nhập 2 thông tin trên.
Cập nhật AndroidManifest.xml
Khai báo vào AndroidManifest.xml với nội dung bổ sung AbxPushReceiver.
<receiver android:name="com.igaworks.v2.core.push.notification.AbxPushReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE"/> <action android:name="com.igaworks.v2.core.pushServiceImplement.CLIENT_PUSH_RECEIVE"/> </intent-filter> </receiver>
Khai báo vào AndroidManifest.xml với service sau đây:
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Gửi Notification Token về AdBrix
Để gửi FCM token về cho adbrix sử dụng hàm AdBrixRm.setRegistrationId() trong một class MyFirebaseMessagingService mở rộng từ FirebaseMessagingService như sau:
class MyFirebaseMessagingService : FirebaseMessagingService(){ override fun onNewToken(token: String?) { Log.d(TAG, "Refreshed token: $token") // If you want to send messages to this application instance or // manage this apps subscriptions on the server side, send the // Instance ID token to your app server. // Send token data to Adbrix AdBrixRm.setRegistrationId(token) } }
Push on / off
Khi muốn thiết bị nhận/ không nhận push notification, dùng hàm AdBrixRm.setPushEnable() với giá trị tương ứng .
AdBrixRm.setPushEnable(true) // Push On AdBrixRm.setPushEnable(false) // Push Off
[[인용:경고:보통]]Chú ý về giá trị PushEnable mặc định
Giá trị mặc định là 'Push off'. Vì thế, phải sử dụng hàm trên để thay đổi giá trị 'Push On' để thiết bị có thể nhận tin nhắn.
Thời điểm tốt nhất để gọi hàm này là sau khi nhận được "permission" từ phía người dùng cho phép gửi/nhận push message.
[[인용:안내:보통]] Xin chúc mừng bạn đã tích hợp xong dịch vụ Growth Action~!
Chúng ta đã hoàn thành bước tích hợp cơ bản cho phép AdBrix Server gửi Push Notification cho người dùng. Ngoài ra, để sử dụng các hàm tạo local notification, hãy tham khảo các hàm bên dưới thêm.
Growth Action cài đặt bổ sung
Cài đặt push Icon Style
Cấu hình màu sắc tên app và các loại icon.
AdBrixRm.setPushIconStyle(this,"smallicon","largeicon",Color.argb(1,255,0,0)) //Using Color class ARGB AdBrixRm.setPushIconStyle(this,"smallicon","largeicon",AdBrixRm.PushColor.Yellow) // Using AdBrixRm class
Với cấu hình trên, chúng ta có kết quả như sau:
[[인용:위험:보통]]Chú ý
1) Chú ý đối với giá trị icon name, chỉ cần ghi tên file, không cần kèm extension của file.
2) Toàn bộ file ảnh icon ở các độ phân giải khác nhau phải nằm trong nhóm thư mục Drawable.
3) Nếu cài đặt cả largeIcon, thì nó sẽ được ưu tiên hiển thị cao hơn.
4) Sử dụng tham số ARGB để thay đổi màu cho tên app trong notification.
5) Tham số ARGB, sử dụng lớp Color.argb hoặc AdBrixRm.PushColor như ví dụ đều được.
Cấu hình Push Notification
Cài đặt mức độ ưu tiên của notification và tính visibility ở màn hình lockscreen.
AdBrixRm.setNotificationOption(this,NotificationCompat.PRIORITY_MIN,NotificationCompat.VISIBILITY_SECRET)
Cấu hình cho heads-up notification (PRIORITY)
- PRIORITY_MAX : Sử dụng heads-up notification
- PRIORITY_HIGH : Sử dụng heads-up notification
- PRIORITY_DEFAULT : Không dùng heads-up notification
- PRIORITY_LOW : Không dùng heads-up notification
- PRIORITY_MIN : Không dùng heads-up notification
Cấu hình notification visibility ở lockscreen (VISIBILITY)
- VISIBILITY_SECRET : Do not reveal any part of this notification on a secure lockscreen
- VISIBILITY_PRIVATE : Show this notification on all lockscreens, but conceal sensitive or private information on secure lockscreens
- VISIBILITY_PUBLIC : Show this notification in its entirety on all lockscreens
Cài đặt Push Notification Listener
Cấu hình Local và Remote Push Notification Listener tại MainActivity của ứng dụng như sau:
class MainActivity : AppCompatActivity(), AdBrixRm.onTouchRemotePushListener,AdBrixRm.onTouchLocalPushListener{ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) AdBrixRm.onTouchRemotePushListener(this) // Server Push AdBrixRm.onTouchLocalPushListener(this) // Local Push } // Local Push Listener override fun onTouchLocalPush(onTouchLocalPushString: String?) { Log.d("my_tag", "onReceiveLocakPushmessage" + onTouchLocalPushString) } // Remote Push Listener override fun onTouchRemotePush(onTouchRemotePushString: String?) { Log.d("my_tag", "onReceiveRemotePushMessage" + onTouchRemotePushString) } }
Khi nhấp vào notification, listener sẽ nhận được những thông tin như sau:
- Local push : Toàn bộ thông tin notification được cài đặt.
- Remote push: Nhận được giá trị deeplink đi kèm với notification.
Cấu hình Local push
Text push
Các tham số để nhận local push với định hướng chủ đạo là text.
val bigTextPushMessageProperties = AdBrixRm.BigTextPushProperties() .setTitle("PushTest") .setContentText("This is ContentText") .setBigContentTitle("BigContentTitle") .setSummaryText("Summary Text") .setBigText("This is big Text.This is big Text.This is big Text.This is big Text.This is big Text.") .setSecond(5) .setEventId(12345) .setDeepLinkUri("adbrixrm://main") AdBrixRm.setBigTextClientPushEvent(this,bigTextPushMessageProperties, true)
Giá trị của tham số:
- setSecond : Sau n giây thì notification sẽ được hiển thị
- setEventId : ID của local push notification
- setDeeplinkUri : Giá trị deeplink uri đã cài đặt lúc tạo notification
- bool alwaysShown : Giá trị quyết định xem khi app đang chạy thì có hiển thị notification hay không.
Image Push
Định hướng notification định dạng text lẫn image.
val bigPicturePushProperties = AdBrixRm.BigPicturePushProperties() .setTitle("ImagePushTest") .setContentText("This is ContentText") .setBigContentTitle("BigContentTitle") .setSummaryText("Summary Text") .setBigPictureUrl("http://myimage/image.png") .setResourceId(R.drawable.adbrix_image) .setSecond(10) .setEventId(67890) .setDeepLinkUri("adbrixrm://main") AdBrixRm.setBigPictureClientPushEvent(this,bigPicturePushProperties,true)
Giá trị tham số
- setBigPictureUrl
_ URL của image
_ Nếu sử dụng cả hàm setResourceId() thì giá trị của ResourceId sẽ được ưu tiên sử dụng trước. - setResourceId
_ ResourceId của ảnh
_ Nếu sử dụng cả hàm setBigPictureUrl() thì giá trị của ResourceId sẽ được ưu tiên sử dụng trước. - setSecond : Sau n giây thì notification sẽ được hiển thị
- setEventId : ID của notification
- setDeeplinkUri : Giá trị deeplink của notification
- bool alwaysShown : Giá trị quyết định xem khi app đang chạy thì có hiển thị notification hay không.
[[인용:경고:보통]] Tỉ lệ ảnh nên để 2:1 và độ phân giải tối đa nên là 1350x675.
Hủy local push notification
Có thể hủy quản lý được toàn bộ local Push Notification và hủy notification khi đang trong thời gian đợi chưa được hiển thị bằng hàm AdBrixRm.cancelClientPushEvent().
val localPushList = AdBrixRm.getPushEventList() // Current Local push List(JSON Array) AdBrixRm.cancelClientPushEvent(this,67890) // Cancel the Local Push with EventId 67890
- getPushEventList : Trả về danh sách các notification đang trong hàng đợi mà chưa được hiển thị. Định dạng kết quả trả về là JSON Array.
- cancelClientPushEvent : Sử dụng Notification ID để hủy local notification đang trong hàng đợi.
Bình luận
0 bình luận
Vui lòng đăng nhập để viết bình luận.