2012-04-18 6 views
0

私はアンドロイドアプリのプッシュ通知を機能させようとしています。私のアンドロイド4デバイスの通知を受け取ったので、サーバーはOKと思われます。しかし、Android 2.2.1と2.3.4の通知を受信しない他のデバイスがあります。ここでアンドロイドC2DM通知はアンドロイド4より前に動作していませんか?

は私のC2DMReceiverです:

package vex.android; 

import java.io.IOException; 

import vex.android.settings.Local; 
import vex.android.tool.Resources; 
import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Context; 
import android.content.Intent; 
import android.util.Log; 

import com.google.android.c2dm.C2DMBaseReceiver; 

public class C2DMReceiver extends C2DMBaseReceiver { 

    public C2DMReceiver() { 
     super(Local.PushNotificationEmail); 
    } 

    @Override 
    public void onError(Context context, String errorId) { 
     Log.e("VEX-PUSHNOTIFICATION", "Error " + errorId); 
    } 

    @Override 
    protected void onMessage(Context context, Intent intent) { 

     String saleTitle = Resources.getString("pushnotificationtitle", context); 
     String saleMessage = intent.getStringExtra("salemessage"); 
     String SaleId = intent.getStringExtra("saleid"); 
     String isMultiSale = intent.getStringExtra("ismultisale"); 

     Boolean multisale = (isMultiSale != null && isMultiSale.length()>0) ? Boolean.parseBoolean(isMultiSale.trim()) : false; 
     Integer saleid = (SaleId != null && SaleId.length()>0) ? Integer.parseInt(SaleId.trim()) : -1; 
     if(saleMessage == null || saleMessage.length() <= 0) saleMessage = Resources.getString("pushnoticationmessage", context); 
     createNotification(context, saleTitle, saleMessage, saleid, multisale); 
    } 

    public void createNotification(Context context,String SaleTitle, String SaleMessage, Integer saleid, Boolean multisale) { 

     NotificationManager notificationManager = (NotificationManager) context 
       .getSystemService(Context.NOTIFICATION_SERVICE); 
     Notification notification = new Notification(R.drawable.applicationicon, 
       "Message received", System.currentTimeMillis()); 
     // Hide the notification after its selected 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 

     Intent intent = new Intent(context, MainApplication.class); 
     intent.putExtra("saleid", saleid); 
     intent.putExtra("ismultisale", multisale); 
     PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // without flag a changed saleid wont be passed 
     notification.setLatestEventInfo(context, SaleTitle, SaleMessage, pendingIntent); 
     notificationManager.notify(saleid, notification); 
    } 

    @Override 
    public void onRegistered(Context context, String registrationId) 
    throws IOException 
    { 
     Local.setRegistrationId(registrationId); 
    } 

    @Override 
    public void onUnregistered(Context context) 
    { 
      Log.i("VEX-DEBUG", "successfully unregistered with C2DM server"); 
    } 

} 

私は(カールして)手動で通知を送信する場合、それはアンドロイド2.2と2.3で動作しない場合ため、問題があると思います。何か案が?ありがとう

答えて

1

C2DMはGoogle Messaging Serviceを使用します。 GTalkはこのサービスも使用します。場合によっては、このサービスがオフになることがあります。すべての関連情報を確認するには、ちょうどこのコードを入力 - *#*#8255#*#*

C2DMはアンドロイド> = 2.2

+0

とデバイス上で利用可能であり、ところで - あなたはいつものGoogleアカウントにログインする必要がありますあなたのデバイスがC2Dメッセージを受信する –

2

古いAndroidバージョンのデバイスでC2DMを使用しても問題はありませんでした。

テストするデバイスを増やし、コードを確認することをお勧めします。問題は古いデバイスのC2DMサポートの問題ではなく、v2.2以降のAndroidで動作します。