通知大文本的Android GCM [英] Notification Big Text Android GCM
问题描述
我遇到了麻烦Android的大文本通知的工作如下记载:<一href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.BigTextStyle.html"相对=nofollow> NotificationCompat.BigTextStyle 。这里的code我用来显示通知。我知道所有的数据都回来了正确的,因为我可以得到它显示在控制台上,并作为传统内容的文字和标题。难道我做错了什么?我需要定义bigTestStyle别的地方呢?希望你们中的一个已经这样做过,知道什么可能会丢失。谢谢你。
我的code:
NotificationCompat.BigTextStyle bigTextStyle =新NotificationCompat.BigTextStyle();
bigTextStyle.bigText(extras.getString(信息));
NotificationCompat.Builder bigTextNotification =新NotificationCompat.Builder(上下文)
.setContentTitle(我的应用)
.setContentIntent(pendingIntent)
.setContentText(消息:)
.setSound(soundUri)
.setTicker(extras.getString(信息))
.setWhen(System.currentTimeMillis的())
.setSmallIcon(R.drawable.splash)
.setAutoCancel(真)
.setVibrate(新长[] {0,100,200,300})
.setStyle(bigTextStyle);
最终诠释notificationId =(INT)(System.currentTimeMillis的()/ 1000L);
NotificationManager thisone =(NotificationManager)getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
thisone.notify(notificationId,bigTextNotification.build());
从<一个href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.BigTextStyle.html"相对=nofollow> NotificationCompat.BigTextStyle 文档:
辅助类产生大幅面的通知,其中包括大量的文字。 如果平台不提供大幅面的通知,此方法无效。用户总是会看到正常的通知视图。
也许你的平台不支持大幅面的通知。
编辑:
在另一方面,有可能您的问题就在这里:
NotificationCompat.BigTextStyle bigTextStyle =新NotificationCompat.BigTextStyle();
bigTextStyle.bigText(extras.getString(信息));
您未使用的返回值 bigText
。
尝试将其更改为:
NotificationCompat.BigTextStyle bigTextStyle =新NotificationCompat.BigTextStyle();
bigTextStyle = bigTextStyle.bigText(extras.getString(信息));
或
NotificationCompat.BigTextStyle bigTextStyle =新NotificationCompat.BigTextStyle()bigText(extras.getString(信息))。
EDIT2:
启德,崔根源通知布局较旧的Android版本:
保护无效的onMessage(上下文的背景下,意图意图){
//从信息中提取的有效载荷
捆绑额外= intent.getExtras();
如果(临时演员!= NULL){
字符串消息=(字符串)extras.get(信息);
字符串title =(字符串)extras.get(标题);
//添加一个通知状态栏
NotificationManager mManager的=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
意图myIntent =新的意图(这一点,MyActivity.class);
通知通知=新的通知(R.drawable.notification_image,标题,System.currentTimeMillis的());
notification.flags | = Notification.FLAG_AUTO_CANCEL;
RemoteViews内容查看=新RemoteViews(getPackageName(),R.layout.custom_notification);
contentView.setImageViewResource(R.id.image,R.drawable.notification_image);
contentView.setTextViewText(R.id.title,职称);
contentView.setTextViewText(R.id.text,消息);
notification.contentView =内容查看;
notification.contentIntent = PendingIntent.getActivity(this.getBaseContext(),0,myIntent,PendingIntent.FLAG_CANCEL_CURRENT);
mManager.notify(0,通知);
电源管理器PM =(电源管理器)
context.getSystemService(Context.POWER_SERVICE);
WakeLock WL = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,TAG);
wl.acquire(15000);
}
}
I'm having trouble getting Android's Big Text notifications to work as documented here: NotificationCompat.BigTextStyle. Here's the code I'm using to display notifications. I know all the data is coming back correctly because I can get it to display on the console and as the traditional content text and title. Am I doing something wrong? Do I need to define bigTestStyle somewhere else as well? Hopefully one of you has done this before and knows what could be missing. Thanks.
My code:
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.bigText(extras.getString("message"));
NotificationCompat.Builder bigTextNotification = new NotificationCompat.Builder(context)
.setContentTitle("My App")
.setContentIntent(pendingIntent)
.setContentText("Message:")
.setSound(soundUri)
.setTicker(extras.getString("message"))
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.splash)
.setAutoCancel(true)
.setVibrate(new long[] { 0, 100, 200, 300 })
.setStyle(bigTextStyle);
final int notificationId = (int) (System.currentTimeMillis() / 1000L);
NotificationManager thisone = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
thisone.notify(notificationId, bigTextNotification.build());
From NotificationCompat.BigTextStyle documentation :
Helper class for generating large-format notifications that include a lot of text. If the platform does not provide large-format notifications, this method has no effect. The user will always see the normal notification view.
Perhaps your platform doesn't support large-format notifications.
EDIT :
On the other hand, it's possible your problem is here :
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.bigText(extras.getString("message"));
You are not using the return value of bigText
.
Try to change it to :
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle = bigTextStyle.bigText(extras.getString("message"));
or to :
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle().bigText(extras.getString("message"));
EDIT2 :
Costom Notification Layout for older Android versions :
protected void onMessage(Context context, Intent intent) {
// Extract the payload from the message
Bundle extras = intent.getExtras();
if (extras != null) {
String message = (String) extras.get("message");
String title = (String) extras.get("title");
// add a notification to status bar
NotificationManager mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent myIntent = new Intent(this,MyActivity.class);
Notification notification = new Notification(R.drawable.notification_image, title, System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setImageViewResource(R.id.image, R.drawable.notification_image);
contentView.setTextViewText(R.id.title, title);
contentView.setTextViewText(R.id.text, message);
notification.contentView = contentView;
notification.contentIntent = PendingIntent.getActivity(this.getBaseContext(), 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
mManager.notify(0, notification);
PowerManager pm = (PowerManager)
context.getSystemService(Context.POWER_SERVICE);
WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire(15000);
}
}
这篇关于通知大文本的Android GCM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!