Add messages to Notification for Android Auto on Android M and older

In the previous implementation for Android Auto, messages are only added
on Android N and above. In order to support older Android versions, the
messages need to be added always.
This commit is contained in:
Johannes Morgenroth 2017-04-29 19:25:57 +02:00
parent b3d4d0608f
commit adff2baa4a

View file

@ -20,6 +20,7 @@ import android.text.SpannableString;
import android.text.style.StyleSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Pair;
import java.io.FileNotFoundException;
import java.util.ArrayList;
@ -433,8 +434,6 @@ public class NotificationService {
for (Message message : messages) {
String sender = message.getStatus() == Message.STATUS_RECEIVED ? UIHelper.getMessageDisplayName(message) : null;
messagingStyle.addMessage(UIHelper.getMessagePreview(mXmppConnectionService,message).first, message.getTimeSent(), sender);
uBuilder.addMessage(UIHelper.getMessagePreview(mXmppConnectionService,message).first);
uBuilder.setLatestTimestamp(message.getTimeSent());
}
builder.setStyle(messagingStyle);
} else {
@ -462,6 +461,15 @@ public class NotificationService {
}
}
}
/** message preview for Android Auto **/
for (Message message : messages) {
Pair<String,Boolean> preview = UIHelper.getMessagePreview(mXmppConnectionService, message);
// only show user written text
if (preview.second == false) {
uBuilder.addMessage(preview.first);
uBuilder.setLatestTimestamp(message.getTimeSent());
}
}
}
private Message getImage(final Iterable<Message> messages) {