Android锁屏推送通知

时间:2015-03-02 10:30:15

标签: android push-notification google-cloud-messaging android-5.0-lollipop android-4.4-kitkat

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

1 个答案:

答案 0 :(得分:0)

你不能,因为:

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