Can';不再接收通知,Android和GCM

Can';不再接收通知,Android和GCM,android,notifications,google-cloud-messaging,Android,Notifications,Google Cloud Messaging,我试图在我的android应用程序中使用谷歌云消息,一切都很顺利,但一旦我更改了项目的包结构,我就无法收到通知,这是我的新清单文件 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.gcm" android:versionCode="1" android:versionNa

我试图在我的android应用程序中使用谷歌云消息,一切都很顺利,但一旦我更改了项目的包结构,我就无法收到通知,这是我的新清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gcm"
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.example.gcm.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.gcm.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="8"
    android:targetSdkVersion="16" />


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

            <receiver
        android:name="com.example.gcm.utils.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" />

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

    <service android:name="com.example.gcm.services.GCMNotificationIntentService" />

</application>


您没有包括
com.example.gcm.utils.GcmBroadcastReceiver
的代码,但由于您的问题是在更改包后开始的,因此启动intent服务的广播接收器的代码很可能使用
context.getPackageName()
作为intent服务的包,这是不正确的后,你的变化。您应该指定正确的intent服务类包

假设您在接收机中使用了GCM演示中的标准代码,它可能如下所示:

@Override
public void onReceive(Context context, Intent intent) {
    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(),
            GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
}
在这种情况下,将其更改为:

@Override
public void onReceive(Context context, Intent intent) {
    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(GcmIntentService.class.getPackage().getName(),
            GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
}

请检查您的API密钥,它是否使用与u r相同的包名注册,并使用已更改的包。此外,请检查您的设备id,通知是否发送到正确的设备id,或者是否发送到较旧的设备id,例如,由于您所做的更改,它被更改了?事实上,我已经在另一部手机上测试了我的应用程序,它工作了,但在我的手机和其他手机上仍然不工作,您认为问题是什么?仍然没有任何问题,我已经在context.getPackageName()中尝试了这段代码,它在其他移动设备上运行,与gcminentService.class.getPackage().getName()一样运行良好但这两种代码都不适用于我的phone@ZouhairElamraniAbouElassad什么Android版本的手机不工作,什么Android版本的手机工作?它在Adnroid 4.1.2上工作,在Android 4.0.4上仍然不工作,但它曾经对曾经工作的手机重新启动,现在它不工作了,但其他应用程序仍然接收通知,现在我confused@ZouhairElamraniAbouElassad我也很困惑。你能解释一下你在包结构中到底改变了什么吗?你是否更改了应用程序的主程序包?你能发布广播接收机代码吗?