나는이에 C2DM에서 푸시 알림과 함께 제공되는 데이터의 일부를 전달하려는 내 애플 리케이션에 C2DM를 통해 전송 및 수신 알림을 만들 때 intent extras. 이 잘 내 알림을 처음 열 때 작동합니다. 그런 데이터는 활동 상태에 따라 또는 onNewIntent에서 onCreate에서 수신된다.안드로이드 상태 표시 줄 알림 - 의도 두 번째에 이전 엑스트라를 받고
하지만 C2DM을 통해 두 번째 푸시 알림을 보낼 경우는 새로운 데이터로 정확하게 수신하지만 의도에서 엑스트라를 가져올 때 나는 아직도 이전 메시지에서 데이터를 얻을. 내가보고 싶은 제목과 데이터는 통지에 올바르게 표시됩니다. 그래서 뭔가 내 의도가 틀렸어 야합니다. 활동이 실행되는 경우에 발생하며하지 않은 경우.
다음 내가 할 알림을 만들려면 :
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_stat_notify_push, "Message received", System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.defaults |= Notification.DEFAULT_LIGHTS;
Intent intent = new Intent(context, DesktopApp.class);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("msg_id", msg_id);
intent.putExtra("title", title);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
notification.setLatestEventInfo(context, "New message", title + String.valueOf(msg_id), pendingIntent);
notificationManager.notify(0, notification);
그 의도를 읽으려면 :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent myIntent = getIntent(); // this is just for example purpose
int i = myIntent.getIntExtra("msg_id", -1);
if (i != -1) Toast.makeText(this, "Got message! " + String.valueOf(i), Toast.LENGTH_LONG).show();
}
@Override
public void onNewIntent(Intent intent){
super.onNewIntent(intent);
Bundle extras = intent.getExtras();
if (extras != null) {
int i = extras.getInt("msg_id", -1);
if (i != -1) Toast.makeText(this, "Got message! " + String.valueOf(i), Toast.LENGTH_LONG).show();
}
}
어떤 제안?
감사 onNewIntent() 메소드 내 문제를 해결 :) – SAndroidD