简体   繁体   English

如果用户卸载应用程序,如何从数据库中删除GCMRegistered设备ID

[英]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 . 这是我对gcm的代码,当我向所有注册设备ID发送通知时,我的数据库中大约有15000个registered_device_id用于通知,然后显示10000成功和6000不成功。我想从我们的数据库中删除所有6000注册的设备ID,以便得到通知的时间更少。

You need not to do anything in android code. 您无需在android代码中执行任何操作。 GCM is smart enough to handle it. GCM足够聪明来处理它。 So, once our app is uninstalled, GCM will take care of removing that Registration ID from GCM. 因此,一旦我们的应用程序被卸载,GCM将负责从GCM中删除该注册ID。 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. 但是,我们必须从服务器数据库中删除该注册ID,一旦收到GCM的响应“ NotRegistered”,就必须从数据库中删除该特定注册ID。

Following are the sequence of events. 以下是事件的顺序。

  1. The end user uninstalls the application. 最终用户将卸载该应用程序。
  2. The 3rd-party server sends a message to GCM server. 第三方服务器向GCM服务器发送一条消息。
  3. The GCM server sends the message to the device. GCM服务器将消息发送到设备。
  4. The GCM client receives the message and queries Package Manager about whether there are broadcast receivers configured to receive it, which returns false. GCM客户端接收到该消息,并向程序包管理器查询是否有配置为接收该消息的广播接收器,该接收器返回false。
  5. The GCM client informs the GCM server that the application was uninstalled. GCM客户端通知GCM服务器该应用程序已卸载。
  6. The GCM server marks the registration ID for deletion. GCM服务器将注册ID标记为删除。
  7. The 3rd-party server sends a message to GCM. 第三方服务器向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. GCM向第三方服务器返回一条NotRegistered错误消息。一旦收到GCM的此类回应,我们就必须从数据库中删除该特定注册ID。

Follow that link might be use full for you 跟随该链接可能对您有用

Google Cloud Messaging registration id expiration Google Cloud Messaging注册ID到期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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