2012-04-18 53 views
0

我試圖讓推送通知爲我的android應用程序工作。服務器似乎確定,因爲我收到我的android 4設備上的通知。但我有其他設備與android 2.2.1和2.3.4不收到通知。Android的C2DM通知不工作之前的Android 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"); 
    } 

} 

我認爲這個問題是存在的,因爲如果我手動發送通知(帶捲曲)事件不與Android 2.2和2.3工作。任何想法?謝謝

回答

1

C2DM使用Google消息服務。 GTalk也使用這項服務。有時可能會關閉此服務。要檢查所有的相關信息,只需輸入這個代碼 - *#*#8255#*#*

C2DM可與Android設備> = 2.2

+0

而且順便說一句 - 你應該總是在給谷歌帳戶登錄您的設備接收C2D消息 – 2012-04-18 10:58:09

2

我在舊版Android設備上使用C2DM沒有任何問題。

我建議你得到更多的設備來測試,並檢查你的代碼 - 問題不在於缺少舊設備的C2DM支持 - 它可以在v2.2以上的Android上運行。