当前位置: 首页>>代码示例>>Java>>正文


Java NotificationCompat.MessagingStyle方法代码示例

本文整理汇总了Java中android.support.v4.app.NotificationCompat.MessagingStyle方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationCompat.MessagingStyle方法的具体用法?Java NotificationCompat.MessagingStyle怎么用?Java NotificationCompat.MessagingStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.app.NotificationCompat的用法示例。


在下文中一共展示了NotificationCompat.MessagingStyle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseMessageStyleNotification

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
public boolean parseMessageStyleNotification(Notification notification, Bundle extras)
{
    NotificationCompat.MessagingStyle messagingStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(notification);
    if (messagingStyle == null)
        return false;

    title = formatCharSequence(messagingStyle.getConversationTitle());
    if (TextUtils.isEmpty(title))
        title = formatCharSequence(extras.getCharSequence(NotificationCompat.EXTRA_TITLE_BIG));
    if (TextUtils.isEmpty(title))
        title = formatCharSequence(extras.getCharSequence(NotificationCompat.EXTRA_TITLE));
    if (title == null)
        title  = "";

    List<NotificationCompat.MessagingStyle.Message> messagesDescending = new ArrayList<>(messagingStyle.getMessages());
    Collections.sort(messagesDescending, new Comparator<NotificationCompat.MessagingStyle.Message>() {
        @Override
        public int compare(NotificationCompat.MessagingStyle.Message m1, NotificationCompat.MessagingStyle.Message m2) {
            return (int) (m2.getTimestamp() - m1.getTimestamp());
        }
    });

    text = "";
    for (NotificationCompat.MessagingStyle.Message message : messagesDescending)
    {
        String sender;
        if (message.getSender() == null)
            sender = formatCharSequence(messagingStyle.getUserDisplayName());
        else
            sender = formatCharSequence(message.getSender());

        text += sender + ": " + message.getText() + "\n";
    }

    return true;
}
 
开发者ID:matejdro,项目名称:WearVibrationCenter,代码行数:37,代码来源:NotificationTextParser.java

示例2: setMessageStyle

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
/**
 * API >= 24(N) will work
 *
 * @param userDisplayName
 * @param title
 * @param messages
 * @return
 */
@RequiresApi(api = Build.VERSION_CODES.N)
public NotificationEffect setMessageStyle(CharSequence userDisplayName, CharSequence title, NotificationCompat.MessagingStyle.Message[] messages) {
    NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(userDisplayName)
            .setConversationTitle(title);
    for (int i = 0; i < messages.length; i++) {
        messagingStyle.addMessage(messages[i]);
    }
    mBuilder.setStyle(messagingStyle);
    return new NotificationEffect(mContext, mBuilder);
}
 
开发者ID:cfryan1990,项目名称:NotificationCompat,代码行数:19,代码来源:NotificationStyle.java

示例3: sendNotificationForConversation

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
private void sendNotificationForConversation(
        int conversationId,
        String sender,
        String message,
        long timestamp) {

    // A pending Intent for reads.
    PendingIntent readPendingIntent = PendingIntent.getBroadcast(
            getApplicationContext(),
            conversationId,
            getMessageReadIntent(conversationId),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Building a Pending Intent for the reply action to trigger.
    PendingIntent replyIntent = PendingIntent.getBroadcast(
            getApplicationContext(),
            conversationId,
            getMessageReplyIntent(conversationId),
            PendingIntent.FLAG_UPDATE_CURRENT);

    /// TODO: Add the code to create the UnreadConversation.
    /// End create UnreadConversation.

    /// TODO: Add the code to allow in-line reply on Wear 2.0.
    /// End in-line action for Wear 2.0.

    // Add an action to allow replies.
    NotificationCompat.Action replyAction =
            new NotificationCompat.Action.Builder(
                        R.drawable.ic_reply_white_24dp,
                        getString(R.string.reply_action),
                        replyIntent)
                    /// TODO: Add better wear support.
                    .build();


    // Add messages with the MessagingStyle notification.
    NotificationCompat.MessagingStyle messagingStyle =
            new NotificationCompat.MessagingStyle(sender)
                    .addMessage(message, timestamp, sender);

    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(getApplicationContext())
                    .setStyle(messagingStyle)
                    .setDefaults(NotificationCompat.DEFAULT_VIBRATE)
                    .setSmallIcon(R.drawable.notification_icon)
                    .setLargeIcon(BitmapFactory.decodeResource(
                            getApplicationContext().getResources(), R.drawable.android_contact))
                    .setContentText(message)
                    .setWhen(timestamp)
                    .addAction(replyAction)
                    .setContentTitle(sender)
                    .setContentIntent(readPendingIntent)
                    /// TODO: Extend the notification with CarExtender.
                    /// End
                    ;

    Log.d(TAG, "Sending notification " + conversationId + " conversation: " + message);
    NotificationManagerCompat.from(this).notify(conversationId, builder.build());
}
 
开发者ID:googlecodelabs,项目名称:device-messaging,代码行数:61,代码来源:MessagingService.java


注:本文中的android.support.v4.app.NotificationCompat.MessagingStyle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。