2015-11-19 46 views
1

我是建設和輕鬆的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); 

可以請人幫助我嗎?我找不到任何問題的答案。

在此先感謝。

+0

對不起,我忘了最後的代碼行:mNotificationManager.notify(MESSAGE_NOTIFICATION_ID,mBuilder.build()); –

回答

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()); 

一個例子來幫助你

0

我知道它已經有一段時間,因爲你問到這個問題,但我今天遇到了同樣的問題,找到了sollution。

爲了解決這個問題,你必須覆蓋NotificationCompatsetContentTitlesetContentDescritption

隨着BigTextStyle的:setBigContentTitlebigText 你必須使用他們兩個,裏面同樣的文本。所以,你的代碼看起來像:

String title = "Title"; 
String description = "Description; 

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); 
bigTextStyle.setBigContentTitle(title); 
bigTextStyle.bigText(description); 

NotificationCompat.Builder mBuilder = 
     new NotificationCompat.Builder(this) 
      .setPriority(NotificationCompat.PRIORITY_MAX) 
      .setContentTitle(title) 
      .setContentText(description) 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setStyle(bigTextStyle); 


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


mNotificationManager.notify(0, mBuilder.build());