Edujugon / PushNotification

PHP and Laravel Package to send push notifications to Android and IOS devices.
MIT License
478 stars 159 forks source link

Not getting data in well json formated #18

Closed tribitinfotech closed 7 years ago

tribitinfotech commented 7 years ago

I am sending data by fcm server. but at android side developer getting response like that.

{imag_uri=https://static.pexels.com/photos/4825/red-love-romantic-flowers.jpg, body=Shy7lo Offer, title=Shy7lo Offer}

That is not well formated json response so user getting error while parsing.

Edujugon commented 7 years ago

Hi @tribitinfotech , When send a push notification the package sends a post request to the provider, in your case FCM. That post content is json type always. Then the provider is the one what send the notification to the client/s (devices). So how the data gets the devices is out of the package's scope.

Please recheck how you are parsing the data from your android side.

What is the backend response after sending the notification? Use getFeedback() method after sending notification in order to get the provider response.

tribitinfotech commented 7 years ago

Hi @Edujugon Andtoid side I am using parsing

try { JSONObject json = new JSONObject(remoteMessage.getData().toString());

String title = json.getString("title"); String message = json.getString("body"); String Url = json.getString("imag_uri");

} catch (Exception e) { Log.e(TAG, "Exception: " + e.getMessage()); }

I am getting exception on first line because As I can see in response. there is "" missing in key and value in pushnotification response. I had implemented push notification in android many times and used php server for send push. every time got proper json response. but this time I am using your pushnotification code and not getting valid json push notification response.

Edujugon commented 7 years ago

@tribitinfotech ,

Could you please paste here an example of data you are sending from backend and also the data you are getting in client side? Also, paste here the pushNotification response (getFeedback()).

Edujugon commented 7 years ago

@tribitinfotech ,

Also give a try to the below code:

Map<String, String> params = remoteMessage.getData();
                JSONObject object = new JSONObject(params);
                Log.e("JSON_OBJECT", object.toString());
Edujugon commented 7 years ago

@tribitinfotech ,

From backend you should do something like follows:

$push->setMessage([
    'data' => [
        'imag_uri' => 'https://static.pexels.com/photos/4825/red-love-romantic-flowers.jpg',
        'body'=> 'Shy7lo Offer',
        'title' => 'Shy7lo Offer'
   ]
])->setDevicesToken(HERE-YOUR-TOKENS)
  ->send()
  ->getFeedback();
Edujugon commented 7 years ago

@tribitinfotech , Did you have a chance to try my suggestions?

Edujugon commented 7 years ago

Since I haven't got any reply I assume it was solved...Closing the thread.