使用MySql在Java中实现Google Cloud消息传递

Bry*_*mes 7 java mysql android google-cloud-messaging android-studio

我是一个java开发人员,在mac学习在android studio中编写android代码.我被要求将谷歌云消息集成到一个应用程序中.

据我所知,android studio有一个按钮,可将所有GCM所需内容放入手机/平板电脑应用程序中.但是我不知道它对我的应用程序所做的所有更改以及我不使用谷歌作为数据库的要求.相反,我需要使用mysql的本地实例,因为我们有业务逻辑应用于向特定用户发送消息.

我已经完成了所有谷歌服务器端的任务.我有我的app键,项目密钥...等

当谈到我试图找到的示例和教程时,它们要么过时,要使用与谷歌当前使用的术语不同的术语,使用除了java之外的语言用于服务器端,示例是基于eclipse的,使用第三方库隐藏功能(Kii Cloud)或不使用XMMP(CCS)实现app/server应用程序.

我正在寻找一个直接的java服务器实现教程或示例,它使用XMMP与谷歌进行通信,并安全地与手机/平板电脑上的应用程序以及Android新手可以关注的类进行通信.

我已经完成了这个页面http://developer.android.com/google/gcm/gs.html上的活动,并且我已经按照"后续步骤"中的链接进行了操作,但是他们对我的理解有所了解.还没有.此页面及其链接为我提供了我需要的配置和设置,但没有给出它们的位置和原因.

当我在这方面取得成功时,我的计划是将所有细节压缩到一个关于如何执行此操作的youtube教程中,或者至少是一个非常详细的网页,因为我觉得实现这一点不应该这么难,尤其是使用Java,Tomcat,MySql和Android应用程序.这似乎是开始的基本情况.

Viv*_*day 0

这个问题没有直接的答案 -

请找到下面用 PHP 编写的服务器端代码 -

    <?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of GCM
 *

 */
class GCM {

    //put your code here
    // constructor
    function __construct() {

    }

    /**
     * Sending Push Notification
     */
    public function send_notification($registatoin_ids, $message) {
        // include config
        include_once './config.php';

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

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

        $headers = array(
            'Authorization: key=' . GOOGLE_API_KEY,
            '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);

        // Disabling SSL Certificate support temporarly
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

        // Execute post
        $result = curl_exec($ch);
        if ($result === FALSE) {
            die('Curl failed: ' . curl_error($ch));
        }

        // Close connection
        curl_close($ch);
        echo $result;
    }

}

?>
Run Code Online (Sandbox Code Playgroud)