有没有办法增加 Android 上推送消息的字符数或文本行数?
Is there a way to increase the number of characters or text lines of the push message on Android?
我正在开发 Android 使用推送通知的应用程序。但是,推送消息只显示一行文本。结果,很多通知文本被删减,句子没有意义。
谁能帮我解决这个问题?
是的,这是可能的,使用下面的代码创建可扩展的通知。您可以使用两根手指向下拖动通知文本来展开通知。
public static final int NOTIFICATION_ID = 1;
String msg="your gcm push message";
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),
R.drawable.logo);
PendingIntent contentIntent = null;
public static NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
可扩展通知
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this)
.setSmallIcon(R.drawable.logo)
.setLargeIcon(largeIcon)
.setContentTitle("Title")
.setTicker("Ticker")
.setContentText(msg)
.setStyle(
new NotificationCompat.BigTextStyle().bigText(msg))
.setDefaults(-1);
mBuilder.setAutoCancel(true);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
我正在开发 Android 使用推送通知的应用程序。但是,推送消息只显示一行文本。结果,很多通知文本被删减,句子没有意义。
谁能帮我解决这个问题?
是的,这是可能的,使用下面的代码创建可扩展的通知。您可以使用两根手指向下拖动通知文本来展开通知。
public static final int NOTIFICATION_ID = 1;
String msg="your gcm push message";
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),
R.drawable.logo);
PendingIntent contentIntent = null;
public static NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
可扩展通知
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this)
.setSmallIcon(R.drawable.logo)
.setLargeIcon(largeIcon)
.setContentTitle("Title")
.setTicker("Ticker")
.setContentText(msg)
.setStyle(
new NotificationCompat.BigTextStyle().bigText(msg))
.setDefaults(-1);
mBuilder.setAutoCancel(true);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());