锁屏通知文字

时间:2015-11-19 21:02:29

标签: android notifications android-5.1.1-lollipop

我正在构建和轻松的Android应用程序。 我在通知方面遇到了麻烦。当应用程序收到通知时,它会正确显示所有图片和文本,而在锁定屏幕上,如果手机被锁定,则不会显示文本。要查看文字,我必须向下滑动通知。

这是代码:

NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
            bigText.bigText(body);

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_stat_luceterna_notifica_90)
                    .setContentTitle("Luceterna")
                    .setLargeIcon((((BitmapDrawable) this.getResources().getDrawable(R.mipmap.ic_launcher_lux)).getBitmap()))
                    .setAutoCancel(true)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

            mBuilder.setStyle(bigText);

            Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

            mBuilder.setSound(alarmSound);

            NotificationManager mNotificationManager = (NotificationManager) context
           .getSystemService(Context.NOTIFICATION_SERVICE);

可以请任何人帮助我吗?我找不到任何问题的答案。

提前致谢。

2 个答案:

答案 0 :(得分:1)

我知道你提出这个问题已经有一段时间了,但我今天遇到了同样的问题,并找到了解决方法。

要解决此问题,您必须覆盖 NotificationCompat #import "Transformations.h" @interface Transformations () { // 1 // Depth float _depth; } @end @implementation Transformations - (id)initWithDepth:(float)z Scale:(float)s Translation:(GLKVector2)t Rotation:(GLKVector3)r { if(self = [super init]) { // 2 // Depth _depth = z; } return self; } - (void)start { } - (void)scale:(float)s { } - (void)translate:(GLKVector2)t withMultiplier:(float)m { } - (void)rotate:(GLKVector3)r withMultiplier:(float)m { } - (GLKMatrix4)getModelViewMatrix { // 3 GLKMatrix4 modelViewMatrix = GLKMatrix4Identity; modelViewMatrix = GLKMatrix4Translate(modelViewMatrix, 0.0f, 0.0f, -_depth); return modelViewMatrix; } @end setContentTitle

使用 BigTextStyle setContentDescritptionsetBigContentTitle 你必须使用它们,里面有相同的文字。所以,你的代码看起来像:

bigText

答案 1 :(得分:0)

NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher) // notification icon
            .setContentTitle("Notification!") // title for notification
            .setContentText("Hello word") // message for notification
            .setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());

帮助您的一个例子