Android广播接收机与GMC

Android广播接收机与GMC,android,android-intent,google-cloud-messaging,android-broadcast,Android,Android Intent,Google Cloud Messaging,Android Broadcast,我有这样的问题。我尝试使用谷歌消息云,我需要从一个活动中注册一个BroadCastReceiver,然后从另一个活动中注销它。为此,我将BroadcastReceiver放在活动之外的另一个包中。 在活动中,我有以下几点: public void onPushStateButtonClicked(View view) { // controllo se il bottone è su on boolean on = ((ToggleButt

我有这样的问题。我尝试使用谷歌消息云,我需要从一个活动中注册一个BroadCastReceiver,然后从另一个活动中注销它。为此,我将BroadcastReceiver放在活动之外的另一个包中。
在活动中,我有以下几点:

    public void onPushStateButtonClicked(View view) {
            // controllo se il bottone è su on
            boolean on = ((ToggleButton) view).isChecked();
            PushClientService p = new PushClientService();
            if (on) {
                // se il bottone  in impostazioni è settato ad on registro il dispositivo
                p.customReceiver(this);
                p.pushService(this);
            }else if(!on) {
                // se il bottone  in impostazioni è settato ad off cancello il dispositivo

                try{    
                    GCMRegistrar.unregister(this);
                    p.customUnregisterReceiver(this);

                }catch(IllegalArgumentException iAE){
                    Log.e("Errore:","device non registrato "+iAE);
                }
            }
}
private final BroadcastReceiver mHandleMessageReceiver =
            new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
                Log.d("Message",newMessage);
            }
        };
        public void customReceiver(Context context){
            context.registerReceiver(mHandleMessageReceiver,
                    new IntentFilter(DISPLAY_MESSAGE_ACTION));
        }
        public void customUnregisterReceiver(Context context){
            context.unregisterReceiver(mHandleMessageReceiver);
        }
在另一节课上,我有:

    public void onPushStateButtonClicked(View view) {
            // controllo se il bottone è su on
            boolean on = ((ToggleButton) view).isChecked();
            PushClientService p = new PushClientService();
            if (on) {
                // se il bottone  in impostazioni è settato ad on registro il dispositivo
                p.customReceiver(this);
                p.pushService(this);
            }else if(!on) {
                // se il bottone  in impostazioni è settato ad off cancello il dispositivo

                try{    
                    GCMRegistrar.unregister(this);
                    p.customUnregisterReceiver(this);

                }catch(IllegalArgumentException iAE){
                    Log.e("Errore:","device non registrato "+iAE);
                }
            }
}
private final BroadcastReceiver mHandleMessageReceiver =
            new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
                Log.d("Message",newMessage);
            }
        };
        public void customReceiver(Context context){
            context.registerReceiver(mHandleMessageReceiver,
                    new IntentFilter(DISPLAY_MESSAGE_ACTION));
        }
        public void customUnregisterReceiver(Context context){
            context.unregisterReceiver(mHandleMessageReceiver);
        }
这是舱单:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <permission android:name="com.example.testpushcall.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="com.example.testpushcall.permission.C2D_MESSAGE" /> 
    <!-- App receives GCM messages. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <!-- GCM connects to Google Services. -->
    <uses-permission android:name="android.permission.INTERNET" /> 
    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.testpushcall.TestPush"
            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.testpushcall.utils.CustomGCMBroadcastReceiver" 
            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.testpushcall" />
          </intent-filter>
        </receiver>
        <service android:name="com.example.testpushcall.utils.GCMIntentService" />
    </application>

</manifest>
?xml version=“1.0”encoding=“utf-8”>
当我注销接收者时,mHandleMessageReceiver的值与注册值不同,我该怎么做?使mHandleMessageReceiver为静态


请给我一个想法,我只使用清单中声明的接收者就解决了这个问题。
并从google服务器注册和注销id

我只使用清单中声明的接收者解决了这个问题。 并从google服务器注册和注销id