я использую следующий код в GCMIntentService.javaPush уведомления не показывает в спящем режиме
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire(15000);
wl.acquire();
но толчок уведомления не показывать в спящем режиме.
Push уведомление работает нормально, когда я разблокирую свой телефон, а затем получаю уведомление должным образом.
но я хочу показать уведомление в спящем режиме, как звук воспроизведения звука и получать уведомление от приложения gmail. пожалуйста, помогите, как я могу это сделать.
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message" + intent.getStringExtra("message"));
String message = intent.getStringExtra("message");// getString(R.string.gcm_message);
generateNotification(context, message);
}
private static void generateNotification(Context context, String message) {
int icon = R.drawable.logo;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, Tabs.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.sound);
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
//notification.defaults = Notification.DEFAULT_ALL;
notificationManager.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);
}
уже называют @karan – Rohit
я проверил в отладке, отладчик не идет работать, когда запрос отправить с сервера, отладчик входит в функцию, когда я разблокировать экран – Rohit
см это анс :: http://stackoverflow.com/a/17154181/1944782 –