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

时间:2013-10-21 07:29:11

标签: java android backend

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) {

    }
}

这是我的gcm代码我在我的数据库中有大约15000个registered_device_id用于通知我向所有注册设备ID发送通知然后它显示10000成功和6000不成功。我想从我们的数据库中删除所有6000注册设备ID所以它需要更少的时间来获得通知。

2 个答案:

答案 0 :(得分:1)

你不需要在Android代码中做任何事情。 GCM非常聪明,可以处理它。因此,一旦我们的应用程序被卸载,GCM将负责从GCM中删除该注册ID。但是,我们必须从我们的服务器数据库中删除该注册ID,一旦我们从GCM获得“NotRegistered”的响应,我们就必须从我们的数据库中删除该特定的注册ID。

以下是事件序列。

  
      
  1. 最终用户卸载该应用程序。
  2.   
  3. 第三方服务器向GCM服务器发送消息。
  4.   
  5. GCM服务器将消息发送到设备。
  6.   
  7. GCM客户端收到消息并查询Package Manager是否有广播接收器配置为接收它,   返回false。
  8.   
  9. GCM客户端通知GCM服务器已卸载该应用程序。
  10.   
  11. GCM服务器标记要删除的注册ID。
  12.   
  13. 第三方服务器向GCM发送消息。
  14.   
  15. GCM向第三方服务器返回NotRegistered错误消息。一旦我们从GCM收到此类响应,我们必须   从我们的数据库中删除该特定注册ID。
  16.   

答案 1 :(得分:0)

关注该链接可能会为您使用

Google Cloud Messaging registration id expiration