android - 如何在 Android 的 GCM 通知中实现 "tap-hold and pull down to show the entire message"

标签 android

我正在编写一些 Android 代码来处理 GCM 通知。我在大多数应用程序中看到,当通知到来时,它会以简短文本的形式显示在主屏幕上,但是当我们按住它并向下拉时,它也会显示消息的其余部分。我想在我的代码中实现它。我的代码是这样的:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                    .setLargeIcon(bm)
                    .setSmallIcon(R.drawable.some_pic)
                    .setContentTitle("Some Title")
                    .setContentText(message)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);

但是还是不行。我还需要添加什么,以便它不仅显示末尾带有“...”的单行文本,而且在下拉通知时显示整个消息?

最佳答案

我认为通知的可扩展 View 将帮助您以可扩展模式显示整个消息。 你可以使用这样的扩展 View 吗?

  RemoteViews expandedView=new RemoteViews(context.getPackageName(),
   R.layout.notification_expendable_view);
 expandedView.setTextViewText(R.id.notification_expendable_text,
 your entire message);
Notification notification = notificationBuilder.bulid();
notification.bigContentView = expandedView;
    NotificationManager notificationManager =  
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(101, notification);

以及布局文件夹名称中带有 notification_expendable_view 的布局文件。

notification_expendable_view.xml

 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
    android:id="@+id/notification_expendable_text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
  </LinerLayout>

关于android - 如何在 Android 的 GCM 通知中实现 "tap-hold and pull down to show the entire message",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34149571/

相关文章:

android - 检测漫游事件?

java - Firebase 数据库查询未显示在屏幕上

java - Android:下载的图像未显示在 ListView 中

c# - MyFirebaseMessagingService android :exported needs to be explicitly specified for element

java - 如何以编程方式从android中的url解析XML

android - 检测相机是否已经打开

android - 图片在 react-native 应用程序发布版本中不可见

java - 适用于 Android 应用程序的 REST API

android - 在我重新启动模拟器之前,删除的图像仍然显示在 android 图库中

java - 具有两个键的高效数据结构