Untitled
plain_text
21 days ago
1.3 kB
3
Indexable
Never
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 } } }