简体   繁体   中英

How can I unregister user's device directly from Google's GCM server?

I want to let users to toggle to select whether or not they want to receive notifications on their devices, I am able to remove deviceID from my server using a web service call, however the devices still receive notifications so I figured out that the deviceID still lives on GCM server, I tried using GCMRegistrar.unregister(context); but it has no effect and I still receive notifications.

Can someone please help me with this, I have no clue how to shut down receiving notifications, is there some other way?

This is my BroadcastReceiver

  <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>

                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

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

It can be easily controlled by following:

  1. User selects "I don't want to get notified anymore"
  2. App notifies your push server.
  3. Your server remove the GCM id record in the DB.

You don't have to inform the GCM server. Because your server is not going to send anything to this phone anymore. If the user still get, it's your server bug.

Later, if the user decided to receive again. Just inform the gcm id to your push server again.


To block the message on Client side, there are 2 ways:

1) Unregister your app from gcm by issuing an unregistration Intent. See the first part of this URL .

2) Whenever you receive a push message, check your app setting. If setting is ON, then do sth with the message, eg show notification. If setting is OFF, ignore the message.


The advantage of server side blocking is you have strict control over which users can receive message. Eg The subscription expire, you will want to delete the record from server directly instead of relying on client to block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM