小编zin*_*tro的帖子

打开应用后,应用未显示接收FCM的通知

当我从Firebase发送推送消息时,如果该应用程序处于后台或关闭状态,我会收到通知,但是当该应用程序处于打开状态时则不会...

调试我观察到它特别在onMessageReceived处在MyMessagingService中停止,所以我想我的问题与生成通知有关(或者可能与通知有关)。

我已经实现了该服务:

public class MyMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyMessagingService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    if(remoteMessage!=null)
    {
        String id = null;
        String title = null;
        String message = null;
        String launchPage = null;

        if(remoteMessage.getNotification()!=null)
        {
            if(remoteMessage.getNotification().getTitle()!=null)
            {
                title = remoteMessage.getNotification().getTitle();
            }

            if(remoteMessage.getNotification().getBody()!=null)
            {
                message = remoteMessage.getNotification().getBody();
            }
        }

        if(remoteMessage.getMessageId()!=null)
        {
            id = remoteMessage.getMessageId();
        }

        Log.e(TAG, "id: " + id);
        Log.e(TAG, Consts.TITLE + title);
        Log.e(TAG, Consts.MESSAGE + ": " …
Run Code Online (Sandbox Code Playgroud)

android foreground push-notification firebase firebase-cloud-messaging

5
推荐指数
2
解决办法
8260
查看次数

RecyclerView 与 StaggeredGridLayoutManager :可变的列数和垂直滚动

我想显示一个字符串列表,该列表必须可垂直滚动,并且对于每行都有可变数量的列,该列将取决于字符串。所以它将是一个可垂直滚动的网格。所以从图形上讲我想实现这一点: 在此输入图像描述

我得到的结果是一个可水平滚动的列表,有 3 行和许多列,而我想要的是相反的方式:不可水平滚动(许多列,取决于团队名称),但可垂直滚动。

为了实现这一点,我在回收器视图中添加了一个 StaggeredGridLayoutManager ,其中包含 3 个跨度计数(这可能是错误的)和 StaggeredGridLayoutManager.GAP_HANDLING_NONE ,以拥有尽可能多的列。

第一个问题是是否可以使用 StaggeredGridLayoutManager 来实现这一点?如果是,我该如何解决我的问题?欢迎任何建议或想法。

请注意,xml 中的项目具有最大宽度,然后会省略

我所拥有的是以下内容:item_team.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

    <variable
        name="title"
        type="String" />

</data>

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/margin_small"
    android:background="@drawable/club_background"
    android:padding="@dimen/margin_general">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:ellipsize="end"
        android:maxWidth="184dp"
        android:gravity="center"
        android:lines="1"
        android:text="@{title}"
        tools:text="Arsenal" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

团队适配器.java:

public class TeamAdapter extends ListAdapter<TeamItem, RecyclerView.ViewHolder> {
private LayoutInflater inflater;
private List<TeamItem> items = new ArrayList<>();

private static final DiffUtil.ItemCallback<TeamItem> ITEM_CALLBACK = new DiffUtil.ItemCallback<TeamItem>() {
    @Override
    public boolean areItemsTheSame(@NonNull TeamItem item1, …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview staggeredgridlayoutmanager

3
推荐指数
1
解决办法
1879
查看次数