Android Question [SOLVED]Firebase message (B4A) arrives with Null when app in foreground

kohlenbach

Member
Licensed User
Hi,
when a message arrives (Android) and the app is in foreground, title and body is Null.
What can I do that I dont loose the message content?
 

DonManfred

Expert
Licensed User
Longtime User
How are the Notifications sent?
 
Upvote 0

kohlenbach

Member
Licensed User
I send it from a php page, code like attached. I get title and text when the app is in the background. In the forground only NULL

PHP:
<?php


require_once __DIR__ . '/vendor/autoload.php';

use phpFCMv1\Client;
use phpFCMv1\Config;
use phpFCMv1\Notification;
use phpFCMv1\Recipient;

$client = new Client('service_account.json');

$recipient = new Recipient();
$notification = new Notification();
$config = new Config();

//-----------$config -> setImage(self::TEST_IMAGE);
$title          =  'Test';
$tex            =  'Test from Web';
$TEST_TOPIC     =  '123456';


$recipient ->  setTopicRecipient( $TEST_TOPIC);


$notification -> setNotification($title ,$tex   );
$config -> setPriority(Config::PRIORITY_HIGH);
$client -> build($recipient, $notification, null, $config);
$result = $client -> fire();

echo $result;



?>
 
Upvote 0

kohlenbach

Member
Licensed User
Ok. I solved it. I must send it as notification and data too.
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
    
    Dim mess_title As  String
    Dim mess_body As  String
    
    Dim data As Map = Message.GetData
    If data.IsInitialized Then
        Dim title As String = data.Get("title")
        Dim body As String = data.Get("message")
        Dim timestamp As String = data.Get("timestamp")
    End If
    
    ......
 
Upvote 0
Top