2012-04-18 1 views
0

내 안드로이드 앱을 푸쉬 알림으로 만들려고합니다. 내 안드로이드 장치에서 알림을 받기 때문에 서버가 정상적으로 보입니다. 하지만 안드로이드 2.2.1 및 2.3.4 알림을받지 않는 다른 장치가 있습니다. 나는 그것이 2.2 및 2.3 안드로이드 작동하지 않습니다 내가 (컬로) 수동으로 통지를 보내는 경우 이벤트 때문에 문제가 있다고 생각android C2DM 알림은 android 4 이전에 작동하지 않습니까?

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"); 
    } 

} 

:

여기 내 C2DMReceiver입니다. 어떤 생각? 감사합니다.

답변

1

C2DM은 Google Messaging Service를 사용합니다. GTalk는이 서비스도 사용합니다. 때때로이 서비스가 꺼져있을 수 있습니다. 모든 관련 정보를 확인하려면 바로이 코드를 입력 - * # * # 8255 # * # *

C2DM은 안드로이드와 장치 BTW> = 2.2

+0

그리고 볼 수 있습니다 - 당신은 항상 구글 계정에 로그인해야합니다 C2D 메시지를 수신 할 장치 –

2

이전 Android 버전의 기기에서 C2DM 사용에 문제가 없었습니다.

더 많은 기기를 테스트하고 코드를 확인하십시오. 문제는 오래된 기기에 대한 C2DM 지원 문제가 아니며, v2.2 이상의 Android에서 작동합니다.