Android Question Send Notification

fishwolf

Well-Known Member
Licensed User
Longtime User
I'm sending push notification with php, i have 2 similar methods.

The first show notification through the app, the app receive the fm_MessageArrived event and show the notification with SetInfo and play app sound
the second show notification without use the app.

What is the right method?
Whatis the parameter/s for select the method?

Thanks

B4X:
function FN_SendPushTopic1($ApiUrl, $ApiKey, $Topic, $Title, $Body, $Activity)
{
    $TabMessage = array(
                        'title'    => $Title,
                        'body'     => $Body,
                        'icon'    => 'myicon',  /*Default Icon*/
                        'sound' => 'mySound', /*Default sound*/
                        'activity' => $Activity
                          );
                          
    $TabFields = array(
                        'to'        => '/topics/'.$Topic,
                        'data'    => $TabMessage,
                        );
    
    
    $HttpHeaders = array(
                        'Authorization: key=' . $ApiKey,
                        'Content-Type: application/json'
                        );
                                            
    #Send Reponse To FireBase Server    
    $ch = curl_init();
    curl_setopt( $ch,CURLOPT_URL, $ApiUrl);
    curl_setopt( $ch,CURLOPT_POST, true );
    curl_setopt( $ch,CURLOPT_HTTPHEADER, $HttpHeaders );
    curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $TabFields ) );
    $Result = curl_exec($ch );
    curl_close( $ch );
    
    return json_decode($Result, True);
    
}


B4X:
function FN_SendPushTopic2($ApiUrl, $ApiKey, $Topic, $Title, $Body, $Activity)
{
  // prep the bundle
  $msg = array
  (
    'body' => $Body,
    'title' => $Title,
    'priority' => 'high',
    'sound' => 'default',
    'time_to_live' => 3600
  );
  
  $fields = array
  (
    'to' => '/topics/'.$Topic, 
    'notification' => $msg
  );

  $headers = array
  (
    'Authorization: key=' . $ApiKey,
    'Content-Type: application/json'
  );

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $ApiUrl);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  $result = curl_exec($ch);
  curl_close($ch);
  echo $result;
}
 

fishwolf

Well-Known Member
Licensed User
Longtime User
The example on b4a forum work as first method

 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0
Top