Android Question Send push messages to App from HTML page

Cesaral

Member

Cesaral

Member
You need to send an http request to Firebase server. I'm not sure what you mean with a "html page". It shouldn't be difficult to create a web server with B4J that makes such requests.
I basically want to send data remotely from a web browser to an Android App, having the Google Firebase server in the middle, and no more servers in between.

I have seen these sources to see how to do it:


I guess that a PHP will solve it, but may be there is already an example in this forum that I could use as a template.

Thanks!
 
Upvote 0

Cesaral

Member
I solved this with this PHP code:

B4X:
<?php
function push_notification_php($titulo, $cuerpo) {

    $url = 'https://fcm.googleapis.com/fcm/send';

    /* authorization_key */
    $authorization_key = 'place here yours';

    $fields = array(
          'to'=>'/topics/general',
          'priority'=>'high',
          'data'=>array(
                    'title'=>$titulo,
                    'body'=> $cuerpo
                    )
        );

    $fields = json_encode($fields);


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

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

    $result = curl_exec($ch);
    
    curl_close($ch);

    if (strpos($result, 'message_id') !== FALSE) {
        return true;
        }
    else {
        return false;
        }

}

?>

Now...for some notifications that the App receives, I would need the App to answer the server running the PHP. Any clue about how to do this?

Thanks!
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
need the App to answer the server running the PHP. Any clue about how to do this?
It's already another topic.
Be ready to make PHP-script to receive GET or POST request from your App, answering by HTTPJOB.
 
Upvote 0
Top