如何在Android手機中發送鎖屏推送通知。我的代碼是Android鎖屏推送通知
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.gcm_cloud)
.setContentTitle("Notification")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG"); wl.acquire(15000);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
這不是推送通知。這將通知您在通知欄 – Apurva 2015-03-02 10:38:52
這只是示例。其不完整的代碼部分,如訪問gcm服務器是其他部分。 – 2015-03-02 10:42:18
http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/我嘗試這個併成功,但我也想鎖定屏幕。 – 2015-03-02 10:44:39