how to get the list of devices which are registere

2019-08-23 12:13发布

问题:

after reading the sample code for my server:

// Replace with real BROWSER API key from Google APIs
$apiKey = "123456";

// Replace with real client registration IDs 
$registrationIDs = array( "123", "456" );

// Message to be sent
$message = "x";

// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';

$fields = array(
             'registration_ids'  => $registrationIDs,
             'data'              => array( "message" => $message ),
              );

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

// Open connection
$ch = curl_init();

// Set the url, number of POST vars, POST data
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, json_encode( $fields ) );

// Execute post
$result = curl_exec($ch);

// Close connection
curl_close($ch);

it is required to know the registration_ids from the server to push information.

how to get the list of registered devices (registration_ids) in GCM server from my personal server.

how to send a broadcast message to all devices registered in GCM.

Thank's !

回答1:

how to get the list of registered devices (registration_ids) in GCM server from my personal server

You don't. As you noted, you have to send the registration ID from the device to your server, by one means or another (e.g., Web service).

how to send a broadcast message to all devices registered in GCM

There is no built-in means of doing this, short of you sending a message to all of your registered devices by their registration IDs.