繁体   English   中英

修改Android推送通知(GCN)操作栏中的应用程序图标

[英]Amend the app icon in action bar in Android push notifications (GCN)

我想在通过Google Cloud Notifications发送时发送到应用程序的远程通知中添加图像。

我通过PHP将通知发送给Google。 这本身似乎与我找到的文档完全不符,这告诉我发送'message'参数,实际上它是应用程序上显示的'alert'。

下面是我的PHP代码:

public function send_notification($registation_ids, $message) { 
    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';

    echo 'Message: '.$message.'<br>';

    $fields = array(
        'registration_ids' => $registation_ids,
        'data' => array(
            'message' => $message,
            'alert' => $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) {
        return curl_error($ch);
    }

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

我本以为我只需要发送一个图标和有效载荷,但我找不到任何支持这个的文档。

另一种选择是在应用程序本身上放置图标,然后调用有效负载中的变量来引用该图标,但找不到任何支持该文档的文档。

作为旁注,该应用程序是使用Corona SDK构建的,但我不确定它的相关性。

任何帮助将不胜感激。 谢谢

结果发现,Corona在项目的根目录中查找特定的文件名并使用它。 有3种文件名称格式,每种格式都有不同的DPI版本。 根据我的知识,您不能根据警报的有效负载更改此图标。

白色,适用于Android 3.0及更高版本

IconNotificationDefault-ldpi-v11.png
IconNotificationDefault-mdpi-v11.png
IconNotificationDefault-hdpi-v11.png
IconNotificationDefault-xhdpi-v11.png   

灰色,适用于Android 2.3-3.0

IconNotificationDefault-ldpi-v9.png
IconNotificationDefault-mdpi-v9.png
IconNotificationDefault-hdpi-v9.png
IconNotificationDefault-xhdpi-v9.png

黑色,其他一切

IconNotificationDefault-ldpi.png
IconNotificationDefault-mdpi.png
IconNotificationDefault-hdpi.png
IconNotificationDefault-xhdpi.png

只要您不发送超过4K的数据,您就可以从服务器发送您想要的任何数据。 至于你是否应该发送messagealert ,这完全取决于客户端的代码,因为这是寻找这些参数并使用它们的值的代码。

要直接使用有效负载发送图标,您必须将图像编码为字符串并将该字符串包含在有效负载中(假设它是足够小的图像)。 您的应用必须解码该字符串才能显示图标。 您发送对图标的引用的另一种选择更有意义。 同样,它是必须处理该引用的客户端(应用程序)代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM