Календарь |
| « Май 2015 » | Пн | Вт | Ср | Чт | Пт | Сб | Вс | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
| |
|
Статистика |
|
Онлайн всего: 1 Гостей: 1 Пользователей: 0 | |
|
|
| | |
| Главная » 2015 » Май » 15 » GCM in Android
|
In Developer Console https://play.google.com/apps/publish?hl=en in tab Game Services add new game (button "Add new game"). Fill Game Title and category.
Then in Console https://console.developers.google.com/project you'll see new Project:
Open it. This is your new project info:
Project number you need to fill in Android App to get your registrationID so you can get GCM from this game: registrationID = gcm.register(projectNumber);
Then open APIs tab and selec Cloud Messaging for Android:
Press Enable API, so you'll get such result:
Open Credentials and then press "Create new key" button for public api access:
Choose "Server key":
Then you can fill IPs witch avaliable to send GCM notifications (I set field empty, so any IP can send notification):
Then set API key on your server. Also allowed IPs can be edit any time:
Server example: $api_key = 'AIzaSyAzC2eZQB6ATqOiJigVh7IaR29jWcxuM2M';
$registrationIDs= array("APA91bGetPCtbLbTdyorzlK-0BzkBc0sc1O-ZiFPSt90IceRS_BYrdFxxMBr9y1ZcvCihwm51ZcXnctcHDhBGYG07iCLfXDN_U8sgd7vR682c__FESDuQteTifoXIFSrgH9tM -LrSQ_0DVBJh"); //registrationIDs of android devices $message = array("Test message!"); // Message to be sent
// Set POST variables $url = 'https://android.googleapis.com/gcm/send';
$fields = array( 'registration_ids' => $registrationIDs, 'data' => array( "message" => $message ) // tut lubye polya mogut byt' ); $headers = array( 'Authorization: key='. $api_key, 'Content-Type: application/json' );
$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, json_encode( $fields)); $result = curl_exec($ch); curl_close($ch); ?>
|
Категория: Программирование под Android |
Просмотров: 521 |
Добавил: ScyTer
| Рейтинг: 0.0/0 |
Добавлять комментарии могут только зарегистрированные пользователи. [ Регистрация | Вход ]
| |
| | |
|
|