0

有谁知道一旦设备从 c2dm 注销后我如何从我的 mysql 数据库中删除?我的主要活动有:

public void unregister (View view){
        Log.w("C2DM", "start unregister process");
        Intent unregIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER");
        unregIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));

Toast.makeText(getApplicationContext(), "unregistered", Toast.LENGTH_LONG).show();

        startService(unregIntent);

现在这是我的问题。当我注册时,我将设备 ID 和注册 ID 输入到我的 mysql 数据库中(这有效),一旦单击取消注册,我想删除它

在我的注册接收器中,我有

public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.w("C2DM", "Registration Receiver called");
        if ("com.google.android.c2dm.intent.REGISTRATION".equals(action)) {
            Log.w("C2DM", "Received registration ID");
            final String registrationId = intent
                    .getStringExtra("registration_id");
            String error = intent.getStringExtra("error");

            Log.d("C2DM", "dmControl: registrationId = " + registrationId
                    + ", error = " + error);
            String deviceId = Secure.getString(context.getContentResolver(),
                    Secure.ANDROID_ID);
            createNotification(context, registrationId);
            sendRegistrationIdToServer(deviceId, registrationId);
            // Also save it in the preference to be able to show it later
            saveRegistrationId(context, registrationId);}

sendRegistrationIdToServer 是:

public void sendRegistrationIdToServer(String deviceId, String registrationId) {
        Log.d("C2DM", "Sending registration ID to my application server");
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://myserver.com/Sandbox/androidDevice.php");
        try {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            // Get the deviceID
            nameValuePairs.add(new BasicNameValuePair("Email", deviceId));
            nameValuePairs.add(new BasicNameValuePair("DeviceID",   registrationId));

            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = client.execute(post);
            BufferedReader rd = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent()));

            String line = "";
            while ((line = rd.readLine()) != null) {
                Log.e("HttpResponse", line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

onReceive 和 sendRegistrationIdtoserver 用于设备注册时。现在从上面如果我将我的 php 脚本 (androidDevice.php) 的 url 更改为我的删除脚本,则记录将从我的数据库中删除(当我单击注册按钮时)。所以我知道脚本有效。有没有类似的东西可以用来取消注册,就像注册一样?:

if ("com.google.android.c2dm.intent.REGISTRATION".equals(action)) {

(我有什么意义吗?)任何帮助像往常一样将不胜感激

4

1 回答 1

0

是的,UNREGISTER您可以执行一个意图操作。请参阅Google 的 C2DM 页面 - 取消注册以了解更多信息。

于 2012-05-09T14:52:45.253 回答