Java 如何将文本从应用程序推送到通知栏?

Java 如何将文本从应用程序推送到通知栏?,java,android,Java,Android,是否可以在没有任何服务的情况下将文本从应用程序推送到离线通知栏 检查正确的文档 在这里,我在android中编写了一个函数,以获取文本作为参数,并在android中生成通知 private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); Intent notif

是否可以在没有任何服务的情况下将文本从应用程序推送到离线通知栏

检查正确的文档


在这里,我在android中编写了一个函数,以获取文本作为参数,并在android中生成通知

private void sendNotification(String msg) {
  mNotificationManager = (NotificationManager) this
    .getSystemService(Context.NOTIFICATION_SERVICE);
  Intent notificationIntent = new Intent(this, MainActivity.class);
  notificationIntent.putExtra("NotificationIntent", true);
  notificationIntent.setFlags(Notification.FLAG_AUTO_CANCEL);
  notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
    this).setSmallIcon(R.drawable.ic_launcher)
    .setContentTitle("MDM GCM.")
    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
    .setContentText(msg.toString());
  mBuilder.setAutoCancel(true);
  mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
嘿,我建议你读一读。。