【问题标题】:How to send android push notification from website chat如何从网站聊天发送 android 推送通知
【发布时间】:2015-04-17 01:46:32
【问题描述】:

我已经完成了类似 whatsapp 设计的网站聊天的编程,并且我已经在 android 中创建了应用程序。应用浏览器这个网站聊天(只显示像chrome浏览器这样的网站)。 我需要帮助来了解当用户收到消息时如何在我的应用程序上收到通知 Android 通知应显示“您有新消息”。

我的问题是如何使用推送通知将数据从网站发送到 android

The website chat

【问题讨论】:

    标签: java php android jquery


    【解决方案1】:

    您的 android 应用程序应已注册 GCM,然后您可以从您的网站发送 GCM,然后将其推送到您的应用程序。

    更多详情请见:https://developer.android.com/google/gcm/client.html

    详细教程见:http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

    【讨论】:

    • 我需要方法,不使用互联网?本地连接
    【解决方案2】:
     public function notificationToAndroidAction($pushId){
    
            $url = 'https://android.googleapis.com/gcm/send';
    
            $fields = array(
                'registration_ids' => array($pushId),
                'data' => array("message" => 'hello!'),
            );
    
            $headers = array(
                'Authorization: key=' . GOOGLE_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);
            // Disabling SSL Certificate support temporarily
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    
            $result = curl_exec($ch);
            if ($result === FALSE) {
                die('Curl failed: ' . curl_error($ch));
            }
    
            curl_close($ch);
    
            return 'sent';
        }
    

    【讨论】:

    • 我不能使用谷歌服务器,因为我希望我的项目在没有可变互联网(本地连接)的情况下工作?
    猜你喜欢
    • 1970-01-01
    • 2020-12-17
    • 2016-09-25
    • 2018-01-20
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多