c2dm 을 통해 메세지 push 테스트를 하고 있습니다.
public class C2DMReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i( "C2DMReceiver" , "onReceive called" );
if( intent.getAction().equals( "com.google.android.c2dm.intent.REGISTRATION" )) {
handleRegistration( context, intent );
} else if ( (intent.getAction().equals( "com.google.android.c2dm.intent.RECEIVE" ) ) ) {
Log.i( "C2DMReceiver", "hadleMessage called" );
Log.i( "application state" , Constans.appState );
handleMessage( context, intent );
}
} // end of onReceive();
@SuppressWarnings("deprecation")
private void handleMessage(Context context, Intent intent) {
//Do whatever you want with the message
Log.i( "c2dm", "handleMessage------------------" );
/* 화면켜기 */
PowerManager powerManager = (PowerManager) context.getSystemService( Context.POWER_SERVICE );
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(
PowerManager.SCREEN_DIM_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP
, "TEST_1" );
/* 10초 동안 화면 및 cpu 활성화 */
wakeLock.acquire( 10000 );
/* 진동 */
Vibrator vibrator = (Vibrator) context.getSystemService( Context.VIBRATOR_SERVICE );
vibrator.vibrate( 1000 );
/* 상태바 공지 */
NotificationManager nm = (NotificationManager) context.getSystemService( Context.NOTIFICATION_SERVICE );
Notification notification = new Notification( R.drawable.ic_launcher
, "일정알림"
, System.currentTimeMillis()
);
PendingIntent pendingIntent = PendingIntent.getActivity( context
, 0
, new Intent( context, kr.nicstec.plannote.PlanNoteActivity.class )
, 0
);
notification.setLatestEventInfo(context
, "일정알림"
, intent.getStringExtra( "msg" )
, pendingIntent
);
nm.cancel( 0 );
nm.notify( 0, notification );
Toast.makeText( context, intent.getStringExtra( "msg" ), 50000 ).show();
Log.i( "c2dm", "handleMessage end");
} // end of handleMessage
}
위와 같이 메세지를 수신하고 있습니다.
헌데, 전화기의 상태가 유휴 상태.. 화면이 꺼져있는 상태에서 메세지를 발송하면,
메세지의 알림이 발생할때가 있고, 화면을 켜야 메세지 알림이 발생하는 때가 있습니다.
어떤때는 메세지 알림이 한참 후에 발생하구요.
질문은..
1. 브로드케스트리시버의 단말기의 유휴상태 일때의 작동 순서(?)...
2. 유휴상태에서도 브로드케스트리시버가 작동한다면 c2dm리시버 클래스를 서비스로 등록하지 않아도, 단말기의 상태가 유휴상태일때 메세지를 수신하여 알림을 할 수 있는지 입니다.
두서가 없지만.. 혹시 선배님들의 도움 기다리겠습니다.
테스트 단말기는 갤럭시노트 입니다.
폰이 유휴상태일때든 아니든 메시지를 잘 받았었기 때문에 질문에 대한 답변이 될지 안될지는 모르겠지만...
예상하는 바로는 유휴상태일때가 문제가 되는게 아니라 3g 나 와이파이가 잘터지고 안터지고에 따른 문제가 아닐지 싶습니다.
3g나 와이파이가 잘 터지는 곳에서 실험을 해보고 똑같은 문제가 발생한다면 말씀하신 것 이 문제가 될수가 있겠죠?
저도 알림이 한 참후에 발생했을때가 있었는데 원인은 3g 탓이어서 몇 자 적어 봅니다..