대기중인 에뮬레이터가 잠긴 장치와 동일한 지 여부는 확실하지 않습니다. 이 경우 장치가 잠겨 있어도 알림이 표시되도록하려면 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" />
코드도
다음은 샘플 코드입니다. 감사. 나는 에뮬레이터 동작에 대해서도 확신하지 못했습니다. 나는 나중에 이것을 추가하고 그것을 시도 할 것이다. – Darren
간단한 질문 만합니다. FULL_WAKE_LOCK은 (는) 사용되지 않는 것으로 보입니다. 사용할 대안이 있습니까? – Darren
@Darren 글쎄, 거기에 코멘트 [여기] (http://stackoverflow.com/questions/8662339/how-do-i-use-the-constant-full-wake-lock-in-android4 -0). – Eran