相关疑难解决方法(0)

使用gradle查找依赖树

是否有可能使用gradle来生成依赖于什么的树?

我有一个项目,并希望找出所有的依赖项,所以我可以通过前向声明等来修剪它.

gradle

474
推荐指数
15
解决办法
36万
查看次数

如何在Firebase中的后台应用时处理通知

这是我的清单

    <service android:name=".fcm.PshycoFirebaseMessagingServices">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service android:name=".fcm.PshycoFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
Run Code Online (Sandbox Code Playgroud)

当应用程序处于后台并且通知到达时,默认通知将会运行并且不会运行我的代码onMessageReceived.

这是我的onMessageReceived代码.如果我的应用程序在前台运行,而不是在后台应用程序时,则调用此方法.如何在应用程序处于后台时运行此代码?

// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // If the application is in the foreground handle both data and notification messages here.
    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging

379
推荐指数
17
解决办法
31万
查看次数

当应用程序在后台时,FCM显示重复的通知

我在项目中实施了FCM。推送通知按预期方式工作,在收到通知时调用onMessageReceived。当应用程序位于前台时,这是正确的。

但是,当应用程序在后台运行时,系统托盘始终在到达时显示重复的通知(例如,收到通知A时,系统托盘显示2通知A)。

如何解决这个问题?

编辑:添加代码

我扩展了FirebaseMessagingService类并将其包含在onMessageReceived方法中

这是项目中我使用NotificationManager的唯一部分。

另外,我尝试在此方法上添加日志。当应用程序处于前台时,将调用onMessageReceived。应用程序在后台时不会被调用

@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
    RemoteMessage.Notification notification = remoteMessage.getNotification();

        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        String title = notification.getTitle();
        String message = notification.getBody();

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                .setContentIntent(pendingIntent);


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

        notificationManager.notify(0, notificationBuilder.build());
}
Run Code Online (Sandbox Code Playgroud)

android android-notifications firebase firebase-cloud-messaging

6
推荐指数
3
解决办法
8320
查看次数

在牛轧糖上多次接收FCM通知

我在我的应用程序中使用Firebase推送通知。但是,当我为某个事件发送通知时,仅在Nougat设备上2-3分钟后,我多次收到通知。我在版本低于Nougat的设备上仅收到一条通知。

我检查过服务器一次只发送一个通知。我的应用程式gradle中有低于相依的项目。

compile `com.google.firebase:firebase-messaging:11.8.0`
Run Code Online (Sandbox Code Playgroud)

这是FCM侦听器的代码:

public class MyFcmListenerService extends FirebaseMessagingService {

    @Override
public void onMessageReceived(RemoteMessage remoteMessage) {

  }
}
Run Code Online (Sandbox Code Playgroud)

在清单文件中:

<service android:name="com.myApp.test.fcm.MyFcmListenerService">
  <intent-filter>
     <action android:name="com.google.firebase.MESSAGING_EVENT" />
   </intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging

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