0

如何在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()); 
+0

这不是推送通知。这将通知您在通知栏 – Apurva 2015-03-02 10:38:52

+0

这只是示例。其不完整的代码部分,如访问gcm服务器是其他部分。 – 2015-03-02 10:42:18

+0

http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/我尝试这个并成功,但我也想锁定屏幕。 – 2015-03-02 10:44:39

回答

0

你不能,因为:

  1. Push notifications从一个系统发送到另一个。你只需要一个“常规”通知,这与GCM无关。
  2. 锁屏通知是一个Lollipop功能,你的android-4.4-kitkat问题标签是一个线索。
+0

看到我的评论,这只是示例代码的一部分。 – 2015-03-02 10:47:31

+0

这不幸的只适用于Android 5 – Gorcyn 2015-03-02 10:49:38

+0

任何示例代码? – 2015-03-02 10:54:04