【问题标题】:How to display image using GCM push notification in android如何在 android 中使用 GCM 推送通知显示图像
【发布时间】:2017-08-04 04:56:50
【问题描述】:

我已经成功使用 GCM 在 android 中实现了文本推送通知,但是现在,我想在推送通知时将图像放在状态栏中,如下所示:

我正在使用 jquery 和 javascript 来开发我的应用程序,

这是我的清单:

 <activity android:name="com.plugin.gcm.PushHandlerActivity"/>
<receiver android:name="com.plugin.gcm.CordovaGCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.mypackage" />

这是我的插件结构,

这是我发送通知的 php

$gbr="http://myWeb/image1.jpg";
define( 'API_ACCESS_KEY', 'key');
$registrationIds = array($to);
$msg = array
(
'message' => $message,
'title' => $title,
'vibrate' => 1,
'sound' => 1,
'image'=>$gbr

// you can also add images, additionalData
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );

【问题讨论】:

    标签: jquery cordova push-notification phonegap


    【解决方案1】:

    用图片代替图片

    $msg = array
    (
    'message' => $message,
    'title' => $title,
    'vibrate' => 1,
    'sound' => 1,
    "style"=> "picture",
    "picture"=>"https://www.petfinder.com/wp-content/uploads/2012/11/91615172-find-a-lump-on-cats-skin-632x475.jpg"
    
    // you can also add images, additionalData
    );
    

    【讨论】:

    猜你喜欢
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 2016-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    相关资源
    最近更新 更多