Android Question Push Notification sometimes go head-to-head and sometimes not

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
Hi all,
i'm using push notification in my app I and send notification from a PHP application.
If my message is longer of a row, sometimes notification go head-to-head and sometimes not.
See picture.
Furthermore accented letters are not reported and truncate the message.
Ho may I do?
Thanks
Marco
 

Attachments

  • Screenshot_2017-10-08-08-58-12.png
    115.2 KB · Views: 231

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
How you can see in the picture my problem is "New Line".
In the first notification I can read the message in two lines.
In te second notification the message is in one line only and is truncated.
And how can i solve the problem about "à è ì ò ù" and other particular characters?
 
Upvote 0

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
To send message I need to use PHP and Firebase notification but message is sent UTF-encoded.
hy on the phone don't work accented characters?
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
Are you absolutely sure it's UTF-8 encoded?

For example, while the PHP script itself might be encoded in UTF-8, if the actual text of the notification is being pulled in from elsewhere (eg a database) then you need to make sure that the database field and the database connection are both set to UTF-8, or that you convert characters from whatever the encoding is to UTF8 before constructing the payload you send to Firebase.

There are various tools to do that in PHP, depending on the source of the data and things like whether or not it has HTML entities in it. For example when I was converting a site of mine to change data to UTF8 throughout, I used this to make sure things were converted from Western European (codepage 1252) to UTF8:

B4X:
function convert_string($string) {
   // convert encoding for the new database
   
   return html_entity_decode( mb_convert_encoding($string,'UTF-8','CP1252') ,ENT_HTML5,'UTF-8') ;
}

The mb_convert_encoding function is similar to utf8_encode, but allows you to convert from more than just ISO-8859-1 (which is also western european, but lacking in things like the Euro symbol)
 
Upvote 0

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
The body of push notification is a string. User digits data, then a PHP script read the string via REQUEST.
This is the code:
PHP:
$pno="";
if (isset($_REQUEST['pno'])) {
  $pno = $_REQUEST['pno'];
}
.........
.........
utf8_encode ($pno);
.........
.........
$body=$pno;
$res=sendNotification($apikey,$token,$title,$body);

No DB is used, no JS soutines are used.
I think this is ok.
Then I tried with:
mb_convert_encoding ($pno,'UTF-8','CP1252');
but is the same. Problem not solved.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
utf8_encode ($pno);
try to remove this line. The value coing from b4a should be utf-8 already. No need to convert it again (make is not correct)

BTW: The line DOES nothing.... The correct use would be:

B4X:
$body=$pno;
$res=sendNotification($apikey,$token,utf8_encode ($title),utf8_encode ($body));
 
Upvote 0

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
thanks!!!!
It works!!!

I don't understand why

utf8_encode ($pno);
$body=$pno;
$res=sendNotification($apikey,$token,$title,$body);

is incorrect
and

$res=sendNotification($apikey,$token,utf8_encode ($title),utf8_encode ($body));

is correct

But it works and that's all...
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I don't understand why

utf8_encode ($pno);
$body=$pno;
$res=sendNotification($apikey,$token,$title,$body);

is incorrect
utf8_encode(string) RETURNS the encoded string...
$pno is the same as before after this line.
Correct use if you need it encoded inside the php-script...
B4X:
$pno = utf8_encode ($pno);
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…