3

Android 앱에 알림을 추가하고 있으며 현재 테스트 할 에뮬레이터 만 있습니다. 알림을 받으면 내 GCMBaseIntentService 하위 클래스 (GCMIntentService)의 onMessage() 메소드가 호출됩니다. 여기에서 나타나는 알림을 만듭니다. 에뮬레이터를 대기 모드로 전환하면 알림이 표시되지 않습니다 (장치에서 수신되는 경우 알 수 없음). 알림을 생성하기 전에 WakeLock에 전화를 걸어 장치를 깨울 수 있습니까?알림을 생성하기 전에 WakeLock에 문의해야합니까?

감사합니다.

답변

7

대기중인 에뮬레이터가 잠긴 장치와 동일한 지 여부는 확실하지 않습니다. 이 경우 장치가 잠겨 있어도 알림이 표시되도록하려면 WakeLock에 전화해야합니다.

당신이 당신의 매니페스트에이 권한을 추가해야합니다 물론
@Override 
protected void onMessage(Context context, Intent intent) { 
    // Extract the payload from the message 
    Bundle extras = intent.getExtras(); 
    if (extras != null) { 
     String message = (String) extras.get("payload"); 
     String title = (String) extras.get("title"); 

     // add a notification to status bar 
     NotificationManager mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     Intent myIntent = new Intent(this,MyActivity.class); 
     Notification notification = new Notification(R.drawable.coupon_notification, title, System.currentTimeMillis()); 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 
     RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification); 
     contentView.setImageViewResource(R.id.image, R.drawable.gcm_notification); 
     contentView.setTextViewText(R.id.title, title); 
     contentView.setTextViewText(R.id.text, message); 
     notification.contentView = contentView; 
     notification.contentIntent = PendingIntent.getActivity(this.getBaseContext(), 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT); 
     mManager.notify(0, notification); 
     PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); 
     WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG"); 
     wl.acquire(15000); 
    } 
} 

:

<uses-permission android:name="android.permission.WAKE_LOCK" /> 
+0

코드도

다음은 샘플 코드입니다. 감사. 나는 에뮬레이터 동작에 대해서도 확신하지 못했습니다. 나는 나중에 이것을 추가하고 그것을 시도 할 것이다. – Darren

+0

간단한 질문 만합니다. FULL_WAKE_LOCK은 (는) 사용되지 않는 것으로 보입니다. 사용할 대안이 있습니까? – Darren

+1

@Darren 글쎄, 거기에 코멘트 [여기] (http://stackoverflow.com/questions/8662339/how-do-i-use-the-constant-full-wake-lock-in-android4 -0). – Eran