誰かがデバイスがc2dmから一度登録解除されると私のmysql dbから削除する方法を知っていますか? 私は私の主な活動であります。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);
は今、ここに私の問題があります。私は私のMySQL DBにデバイスIDと登録IDを入力し登録するときである私の登録レシーバ内
をクリックすると登録解除私は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)) {
を登録するためにそこにあるように登録を解除するために使用することができます似たような はい、UNREGISTER
があるいつものように任意のヘルプは