Skip to content

Commit dd85fb4

Browse files
committed
implementing ADMMessageHandlerJob and updating receiver
1 parent 7de8a11 commit dd85fb4

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/ADMMessageHandler.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public class ADMMessageHandler extends ADMMessageHandlerBase {
4444
public static class Receiver extends ADMMessageReceiver {
4545
public Receiver() {
4646
super(ADMMessageHandler.class);
47+
boolean ADMLatestAvailable = false;
48+
try{
49+
Class.forName( "com.amazon.device.messaging.ADMMessageHandlerJobBase" );
50+
ADMLatestAvailable = true ;
51+
}
52+
catch (ClassNotFoundException e)
53+
{
54+
// Handle the exception.
55+
}
56+
if (ADMLatestAvailable) {
57+
registerJobServiceClass(ADMMessageHandlerJob.class, 1);
58+
}
4759
}
4860
}
4961

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
11
package com.onesignal
22

3-
import android.content.Context
43

4+
import android.content.Context
55
import android.content.Intent
6-
7-
86
import com.amazon.device.messaging.ADMMessageHandlerJobBase
97

108
class ADMMessageHandlerJob : ADMMessageHandlerJobBase() {
11-
override fun onMessage(p0: Context?, p1: Intent?) {
12-
TODO("Not yet implemented")
9+
10+
override fun onMessage(context: Context?, intent: Intent?) {
11+
val bundle = intent!!.extras
12+
13+
val processedResult = NotificationBundleProcessor.processBundleFromReceiver(context, bundle)
14+
// TODO: Figure out the correct replacement or usage of completeWakefulIntent method
15+
// FCMBroadcastReceiver.completeWakefulIntent(intent);
16+
17+
// TODO: Figure out the correct replacement or usage of completeWakefulIntent method
18+
// FCMBroadcastReceiver.completeWakefulIntent(intent);
19+
if (processedResult.processed()) return
20+
21+
val payload = NotificationBundleProcessor.bundleAsJSONObject(bundle)
22+
val notification = OSNotification(payload)
23+
24+
val notificationJob = OSNotificationGenerationJob(context)
25+
notificationJob.jsonPayload = payload
26+
notificationJob.context = context
27+
notificationJob.notification = notification
28+
NotificationBundleProcessor.processJobForDisplay(notificationJob, true)
1329
}
1430

15-
override fun onRegistered(p0: Context?, p1: String?) {
16-
TODO("Not yet implemented")
31+
override fun onRegistered(context: Context?, newRegistrationId: String?) {
32+
OneSignal.Log(OneSignal.LOG_LEVEL.INFO, "ADM registration ID: $newRegistrationId")
33+
PushRegistratorADM.fireCallback(newRegistrationId)
1734
}
1835

19-
override fun onUnregistered(p0: Context?, p1: String?) {
20-
TODO("Not yet implemented")
36+
override fun onUnregistered(context: Context?, registrationId: String?) {
37+
OneSignal.Log(OneSignal.LOG_LEVEL.INFO, "ADM:onUnregistered: $registrationId")
2138
}
2239

23-
override fun onRegistrationError(p0: Context?, p1: String?) {
24-
TODO("Not yet implemented")
40+
override fun onRegistrationError(context: Context?, error: String?) {
41+
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "ADM:onRegistrationError: $error")
42+
if ("INVALID_SENDER" == error) OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Please double check that you have a matching package name (NOTE: Case Sensitive), api_key.txt, and the apk was signed with the same Keystore and Alias.")
43+
44+
PushRegistratorADM.fireCallback(null)
2545
}
2646
}

0 commit comments

Comments
 (0)