gpt4 book ai didi

android - 从node-gcm服务器发送但未收到的GCM消息

转载 作者:太空宇宙 更新时间:2023-11-04 02:32:08 25 4
gpt4 key购买 nike

这是node-gcm服务器的结果

**

{ multicast_id: 5309930915296650000,
success: 1,
failure: 0,
canonical_ids: 0,
results: [ { message_id: '0:1410197314824005%31e4cc17f9fd7ecd' } ] }

**

以及我的服务器代码,其中我从 mongoDb 检索 reg_ids 并将它们存储在字符串数组中并将其传递给发送方法

exports.create = function ( req, res ){
new Comment({
// username : req.body.username,
content : req.body.comment,
created : Date.now()
}).save( function( err, comment, count ){
res.redirect( '/' );
});

reg_ids=[];

User.find({},'gcm_id',function(err,res)
{


for(i=0;i<res.length;i++)
{
reg_ids.push(res[i].gcm_id);

console.log(i+'th entry is '+res[i].gcm_id+'\n');

}
// reg_ids=res.toArray();


var message = new gcm.Message();
message.delay_while_idle = 1;
message.addDataWithKeyValue('message',req.body.comment);


sender.send(message, reg_ids, 4, function (err, result) {
console.log(result);




});






});

};

服务器中的一切看起来都很好

和我的接收器在这里我放置了一个 Log.D 来检查接收器是否被触发但事实并非如此

    package com.javapapers.android;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {


Log.d("receiver", "received");
ComponentName comp = new ComponentName(context.getPackageName(),
GCMNotificationIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}

最后是我的 list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.javapapers.android"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<permission
android:name="com.javapapers.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

<uses-permission android:name="com.javapapers.android.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="16" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"

>

<activity
android:name=".RegisterActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.javapapers.android.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name" >
</activity>

<receiver
android:name=".GcmBroadcastReceiver"
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" />
<action android:name="com.google.android.c2dm.intent.GCM_RECEIVED_ACTION"/>

<category android:name="com.javapapers.android" />
</intent-filter>
</receiver>

<service android:name=".GCMNotificationIntentService" />
</application>

</manifest>

我已经被这个问题困扰很久了如果有人能提供帮助,我将不胜感激

最佳答案

您必须添加消息键和值才能发送消息。就像这样:

message.addData('message', 'push notification worked');

关于android - 从node-gcm服务器发送但未收到的GCM消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25730143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com