2012-04-13 2 views
1

이 c2dm 코드 http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html .it works.i를 사용하는 작은 데모를 구현했습니다. 서버에서 푸시 알림을 받고 있지만 문제는 서버에서 알림을 보낼 때마다 이전 알림을 보냅니다. 현재 안드로이드 장치를 등록하고 서버에 등록 ID를 보낼 때마다 최신 새 알림이 나옵니다. 문제가 무엇인지 제안 해주십시오. 미리 감사드립니다.android에서 c2dm 메시징과의 혼동

+0

코드를 보여주십시오. –

+0

콘텐츠 코드는 내 질문에 게시 된 링크와 동일합니다. –

답변

1

Lars Vogel의 튜토리얼을 직접 따라 가면서 기억하는 한, 같은 문제. 실제로 당신이 진술 한 문제는 아닙니다.

수신하는 페이로드를 수동으로 보려면 onReceive() 함수에 중단 점을 넣으십시오. 제 경우에는 메시지가 좋았지 만 MessageReceivedActivity은 아니며 항상 나쁜 메시지를 보여주었습니다.

메시지 상단의 MessageReceivedActivity에서 super.onCreate() 메서드를 넣습니다.

얼마나 :

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    setContentView(R.layout.activity_result); 
    Bundle extras = getIntent().getExtras(); 
    if (extras != null) { 
     String message = extras.getString("payload"); 
     if (message != null && message.length() > 0) { 
      TextView view = (TextView) findViewById(R.id.result); 
      view.setText(message); 
     } 
    } 

    super.onCreate(savedInstanceState); 
} 

어떻게해야 : @RaulGogo에서

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_result); 
    Bundle extras = getIntent().getExtras(); 
    if (extras != null) { 
     String message = extras.getString("payload"); 
     if (message != null && message.length() > 0) { 
      TextView view = (TextView) findViewById(R.id.result); 
      view.setText(message); 
     } 
    } 
} 
0

대답은 조금 도움이,하지만 나를 위해 문제가 해결되지 않았다. 이 해결책을 여기에서 보려면 https://stackoverflow.com/a/10079537/264618와 내 의견을 읽어보십시오. 일반적으로 변화

C2DMMessageReceiver 클래스에서이 코드 :

int ukey = (int) System.currentTimeMillis(); 
PendingIntent pendingIntent = PendingIntent.getActivity(context, ukey, 
      intent, 0); 

및 MessageReceivedActivity 클래스에서이 추가

@Override 
    protected void onNewIntent(Intent intent) { 
     super.onNewIntent(intent); 
     setIntent(intent);//important! 

참고 : setIntent (의도) 호출이 현재 데이터와 의도를 새로 고칩니다.