Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
4
Indexable

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.netcore.android.smartechpush.SmartPush;
import com.netcore.smartech.sample.R;
import com.netcore.smartech.sample.utils.Utility;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;






public class FCM_Service extends FirebaseMessagingService {

@Override
public void onNewToken(@NonNull String token) {
        super.onNewToken(token);
        SmartPush.getInstance(new WeakReference<Context>(this)).setDevicePushToken(token);

        //<Your code>
        }

@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
    boolean pushFromSmartPush = false;
    try {
        pushFromSmartPush = SmartPush.getInstance(new WeakReference<Context>(this)).isNotificationFromSmartech(new JSONObject(remoteMessage.getData().toString()));
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    if(pushFromSmartPush){
        SmartPush.getInstance(new WeakReference<>(getApplicationContext())).handlePushNotification(remoteMessage.getData().toString());
        } else {
        // Notification received from other sources
        }
        }
        }