I am creating and app similar to uber but instead of creating two separate apps i am placing both the driver and passenger activities in the same app... After the driver declines a passenger request a notification is sent to the driver informing them that the driver has decline the request... This notification generates the error:
E/UncaughtException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
in the passenger app compliments of the line
LatLng customer_location = new Gson().fromJson(remoteMessage.getNotification().getBody(),LatLng.class);
Gson File
public interface IFCMService {
@Headers({
"Content-Type:application/json",
"Authorization:key=xxx"
})
@POST("fcm/send")
Call<FCMResponse> sendMessage(@Body Sender body);
}
MyFirebaseMessagingService
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d("EARLYBIRD", remoteMessage.getNotification().getBody());
// Include Latitude and Longitude in firebase message
LatLng customer_location = new Gson().fromJson(remoteMessage.getNotification().getBody(),LatLng.class);
Intent intent = new Intent(getBaseContext(), CustomerCall.class);
intent.putExtra("lat",customer_location.latitude);
intent.putExtra("lng",customer_location.longitude);
intent.putExtra("customer",remoteMessage.getNotification().getTitle());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}