小编Nov*_*kov的帖子

Firebase云消息传递 - onMessageReceived无法正常工作

我想在我的应用中制作一个简单的通知功能.我按照 YouTube视频和这两个Firebase文档网址12以及Android Studio中的Firebase工具助手(说我已连接到Firebase).出于某种原因,在我的旧应用程序(下面发布的代码)上执行这些步骤和文档后,它将不允许我接收通知.但是,如果我在一个全新的应用程序上执行相同的步骤,它将完美地运行.我在后台,活动和终止状态下测试了同一物理设备和环境中的两个应用程序.每次我创建的新演示应用程序都没有问题,但我想要通知的旧应用程序不起作用.两者均未经过设备ID测试.我甚至没有得到任何错误日志或任何TAG日志.我认为我的一个编译项目是干扰的,不确定究竟是什么,但我可能要看那里.

我还检查了所有这些SO帖子:1 2 3及更多

PS.我在下面删除了我的包名,我在FireBase上多次检查并且它们匹配,所以我知道这不是问题.但是,我的新演示应用程序的FireBase显示我的应用程序连接但我的旧应用程序的FireBase没有.此外,我之前已经设置了赏金,但仍然遇到同样的问题.

这是我有问题的代码:

Notification.java(它的文档要求的服务)

public class Notification extends FirebaseMessagingService {
public Notification() {
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    showNotification(remoteMessage.getData().get("message"));

    Log.d("FMC", "Message Notification Body: " + remoteMessage.getNotification().getBody());
}

private void showNotification(String message) {
    Intent i=new Intent(this, SplashScreen.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent=PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder=new NotificationCompat.Builder(this)
            .setAutoCancel(true)
            .setContentTitle("FCM TITLE").setContentText(message)
            .setSmallIcon(R.drawable.pt_icon)
            .setDefaults(android.app.Notification.DEFAULT_ALL)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0,builder.build());
}
}
Run Code Online (Sandbox Code Playgroud)

请注意,我甚至没有在上面的notification.java中登录.

Project.gradle

buildscript {
repositories {
    jcenter()
    maven {
        url 'https://maven.google.com/' …
Run Code Online (Sandbox Code Playgroud)

java android firebase firebase-cloud-messaging

13
推荐指数
3
解决办法
4648
查看次数

如何在枚举中保留值类型

让我们看看下面这段代码,并假设两者MyAttributetest函数都无法更改.

type MyAttribute() =
    inherit Attribute()

    let mutable prop = null

    member this.Prop
        with get(): obj = prop
        and  set(value) = prop <- value


type MyEnum = 
    | A = 1
    | B = 2

[<My(Prop = MyEnum.B)>]
type MyClass = class
    end

let test () =
   let t = typeof<MyClass>
   let a = t.GetCustomAttributes(false).[0] :?> MyAttribute

   let e = a.Prop
   Convert.ToString(e, Globalization.CultureInfo.CurrentCulture)
Run Code Online (Sandbox Code Playgroud)

我希望test返回B但返回2.生成的IL代码显示有关枚举类型的信息丢失,传递给属性的值仅为2.

是否有任何方法(我想应该是某些属性)来保留属性值中的类型?什么更有趣的C#等效代码按预期工作

等价C#:

class MyAttribute : Attribute
{
    public …
Run Code Online (Sandbox Code Playgroud)

enums f# attributes value-type

9
推荐指数
1
解决办法
197
查看次数

使用underscore.js从两个数组中查找A - B.

我必须在javascript中过滤掉数组中的某些元素,并考虑使用underscore.js来实现此目的.由于我是新手,我们非常感谢.请参考下面的代码,我必须找到A\B并将结果分配给C.underscore.js有没有方便的方法呢?

function testUnderScore(){
    alert("underscore test");
    var a = [84, 99, 91, 65, 87, 55, 72, 68, 95, 42];
    var b = [ 87, 55, 72,42 ,13];
    var c = [];

    alert(c);
}
Run Code Online (Sandbox Code Playgroud)

javascript underscore.js

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

数字的正则表达式将字符串与非数字字符匹配

我的正则表达式是@"\d+".但是对于字符串"9r651",它总是返回true.我只是希望它为仅包含数字的字符串(0-9)返回true.我只是想不出来.任何帮助将非常感激.谢谢.

.net c# regex

0
推荐指数
1
解决办法
234
查看次数