푸시 알림 메시지를 표시하는 응용 프로그램을 개발 중입니다. 토스트 메시지를 사용하여 메시지를 표시하려고 할 때 모든 상황에서 올바르게 작동합니다. 하지만 이러한 푸시 알림에 StatusBarNotifications
을 사용하고 싶습니다. 앱이 실행 중일 때 제대로 작동합니다. 종료 한 후 장치를 다시 시작하면 상태 표시 줄 알림이 표시되지 않습니다. 앱이 강제 종료 될 때도 마찬가지입니다.응용 프로그램이 실행되고 있지 않을 때 onReceive 함수의 컨텍스트가 제대로 작동하지 않습니다.
이 문제를 어떻게 해결할 수 있습니까? 다음
는코드입니다 :
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE"))
{
handleMessage(context, intent);
}
}
private void handleMessage(Context context, Intent intent)
{
String message= intent.getStringExtra("msg");
Toast.makeText(context.getApplicationContext(),"\n message : "+message,1).show();
NotificationManager objNotfManager=(NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.logo;
CharSequence tickerMessage = message;
long when= System.currentTimeMillis();
Notification objNotf = new Notification(icon,tickerMessage,when);
CharSequence title = "New message from "+message;
CharSequence mesage = "You have "+number+" unread messages";
Intent NotifIntent = new Intent(context.getApplicationContext(),TabContainer.class);
NotifIntent.putExtra("message",message);
PendingIntent contentIntent = PendingIntent.getActivity( context.getApplicationContext(), 0, NotifIntent, 0);
objNotf.setLatestEventInfo( context.getApplicationContext(), title, mesage, contentIntent);
objNotfManager.notify(1,objNotf);
}
은 이전에 내가 컨텍스트를 사용하지만, 다른 위젯, 다른 토스트 작동하지되었다. 그래서
context.getApplicationContext()
을 사용할 계획이었습니다.
참조 http://stackoverflow.com/questions/6921464/android-context-has-some-problem-when-displaying-push-notification-using-c2dm/8974369#8974369 –