是否可以在没有任何服务的情况下将文本从应用程序推送到通知栏?
答案 0 :(得分:0)
检查正确的文档。
答案 1 :(得分:0)
这里我在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());
}