推送通知无法取消注册

时间:2012-06-13 09:57:49

标签: android push-notification

private void unregister() {
    Intent unregIntent = new Intent(
            "com.google.android.c2dm.intent.UNREGISTER");
    unregIntent.putExtra("app",
            PendingIntent.getBroadcast(this, 0, new Intent(), 0));
    startService(unregIntent);
}

我调用此函数但返回给我

com.google.android.c2dm.intent.REGISTRATION代替com.google.android.c2dm.intent.UNREGISTRATION

当我致电unregister()时,它会运行

if ("com.google.android.c2dm.intent.REGISTRATION".equals(action)) {
        final String registrationId = intent
                .getStringExtra("registration_id");
        String deviceId = Secure.getString(context.getContentResolver(),
                Secure.ANDROID_ID);
        sendRegistrationIdToServer(deviceId, registrationId);
        System.out.println(registrationId.toString());
        // createNotification(context, registrationId);
    }

这是我的androidmanifest.xml,是否需要添加取消注册?

<receiver
        android:name=".C2DM_RegistrationReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="oriental.orientalOnePaper" />
        </intent-filter>
    </receiver>
    <receiver
        android:name=".C2DM_MessageReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="oriental.orientalOnePaper" />
        </intent-filter>
    </receiver>

0 个答案:

没有答案