简体   繁体   中英

how to delete GCMRegistered device id from database if user Uninstall application

public class GCMIntentService extends GCMBaseIntentService {

    NotificationManager mNotificationManager;
    Context cc;

    @Override
    protected void onRegistered(Context context, String regId) {
        Intent intent = new Intent(Constants1.ACTION_ON_REGISTERED);
        intent.putExtra(Constants1.FIELD_REGISTRATION_ID, regId);
        context.sendBroadcast(intent);
    }

    @Override
    protected void onUnregistered(Context context, String regId) {
        Log.i(Constants1.TAG, "onUnregistered: " + regId);
        AlertDialog.Builder alert = new AlertDialog.Builder(
                getApplicationContext());

        alert.show();

    }

    @Override
    protected void onMessage(Context context, Intent intent) {

        /**
         * You can get the Extras from TaxMann server
         * 
         * Bundle _bundle = intent.getExtras();
         */

        String msg = intent.getStringExtra("payload");
        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        BackgroundAlert bg = new BackgroundAlert(mNotificationManager, msg);
        bg.onReceive(getApplicationContext(), intent);
    }

    @Override
    protected void onError(Context context, String errorId) {

    }
}

This is my code for gcm i have approx 15000 registered_device_id in my database for notification when i send notification to all register device id then it show 10000 success and 6000 unsuccessful .i want to delete all 6000 registered device id from our database so that it take less time to get notification .

You need not to do anything in android code. GCM is smart enough to handle it. So, once our app is uninstalled, GCM will take care of removing that Registration ID from GCM. However, we have to delete that registration Id from our server database, once we get the response from GCM as "NotRegistered", we have to remove that particular registration ID from our database.

Following are the sequence of events.

  1. The end user uninstalls the application.
  2. The 3rd-party server sends a message to GCM server.
  3. The GCM server sends the message to the device.
  4. The GCM client receives the message and queries Package Manager about whether there are broadcast receivers configured to receive it, which returns false.
  5. The GCM client informs the GCM server that the application was uninstalled.
  6. The GCM server marks the registration ID for deletion.
  7. The 3rd-party server sends a message to GCM.
  8. The GCM returns a NotRegistered error message to the 3rd-party server.Once, we receive this kinda response from GCM, we have to delete that particular registration ID from our database.

Follow that link might be use full for you

Google Cloud Messaging registration id expiration

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