gpt4 book ai didi

android - 无法接收 gcm 消息

转载 作者:行者123 更新时间:2023-11-30 01:44:47 25 4
gpt4 key购买 nike

我遵循这个最新的教程 https://github.com/codepath/android_guides/wiki/Google-Cloud-Messaging

但是我的接收者没有收到 gcm 消息。

我很确定 gcm 已成功发送,因为服务器端的响应是

{
"multicast_id":8234052701190658472,
"success":1,
"failure":0,
"canonical_ids":0,
"results":
[
{
"message_id":"0:1448357690225369%9aaa71e7f9fd7ecd"
}
]
}

这是我的 list

<uses-permission
android:name="com.my.app.permission.C2D_MESSAGE" />

<!-- [START gcm_receiver] -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
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.my.app" />
</intent-filter>
</receiver>
<!-- [END gcm_receiver] -->

<!-- [START gcm_listener] -->
<service
android:name="com.my.app.MyGcmListenerService"
android:exported="false"
android:process=":remote" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- [END gcm_listener] -->
<!-- [START instanceId_listener] -->
<service
android:name="com.my.app.MyInstanceIDListenerService"
android:exported="false"
android:process=":remote" >
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<!-- [END instanceId_listener] -->

这是 MyGcmListenerService.java。但是,它永远不会被调用。

public class MyGcmListenerService extends GcmListenerService {

/**
* Called when message is received.
*
* @param from SenderID of the sender.
* @param data Data bundle containing message data as key/value pairs.
* For Set of keys use data.keySet().
*/
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("data");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " + message);
}
}

这是我的 gcm 依赖项。

compile 'com.android.support:support-annotations:23.0.1'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile 'com.android.support:appcompat-v7:23.0.0'

为什么我的 android 应用收不到 gcm?

谢谢!

最佳答案

下面的代码适合我

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

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

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

<uses-permission android:name="com.push.gcm.permission.C2D_MESSAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.push.gcm" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.push.gcm" />
</intent-filter>
</receiver>

<service
android:name=".services.GCMInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name=".services.GCMListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>

</manifest>

关于android - 无法接收 gcm 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33890426/

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