gpt4 book ai didi

java - 广播接收器无法接收谷歌云消息

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

我已经学习 Google Cloud Messaging API 好几天了,现在,我的应用程序出错了。首先,我通过 php 构建了我的服务器,它返回有关 GCM 的成功消息,如下所示:

{"multicast_id":7148194663931263470,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1413222862155080%099070adf9fd7ecd"}]}

但是在我的应用程序中,我尝试了很多方法来确保我的应用程序能够收到消息。但是我失败了。我的应用程序没有收到任何东西。

有人帮助我。这是 Manifest.xml:

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

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

<uses-permission android:name="com.dangchienhsgs.giffus.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
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=".HomeActivity"
android:label="@string/title_activity_home" >
</activity>

<receiver
android:name=".GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.dangchienhsgs.giffus" />
</intent-filter>
</receiver>

<provider
android:name=".provider.DataProvider"
android:authorities="com.dangchienhsgs.giffus.provider"
android:exported="false" >
</provider>

<service android:name=".GcmIntentService"/>

<activity
android:name=".RegisterActivity"
android:label="@string/title_activity_register" >
</activity>

<!--<service android:name=".account.AuthenticatorService" >
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>

<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service> -->

</application>

</manifest>

这里是GCMBroadcastReceiver.java

package com.dangchienhsgs.giffus;

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;
import android.widget.Toast;

import com.google.android.gms.gcm.GoogleCloudMessaging;

public class GCMBroadcastReceiver extends WakefulBroadcastReceiver {
private static final String TAG="GCMBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// Sure that GCMIntentService will handle the intent
Log.d(TAG, "is Received");
Log.d(TAG, "Our message is received");
ComponentName comp=new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}


}

这是我的 Github 链接:"https://github.com/dangchienhsgs/Giffus "

最佳答案

我检查了你的消息接收代码,似乎没问题。

您是否将设备注册到 GCM:https://developer.android.com/google/gcm/client.html#sample-register

关于java - 广播接收器无法接收谷歌云消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26346110/

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