在主从应用程序中显示通知-没有错误,但也没有通知 [英] Displaying Notifications in Master-Detail app - no error but no notification either

查看:106
本文介绍了在主从应用程序中显示通知-没有错误,但也没有通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Xamarin应用中接收通知,最初是在Android方面,然后我将在iOS上进行.我下载了android 示例应用,它运行良好.但是,当我尝试在自己的应用程序中实现相同功能时,尽管我没有收到任何错误,但也没有收到任何通知.

I'm trying to get notifications going in a Xamarin app, initially in the Android side, then I'll do the iOS. I downloaded the android sample app and it works just fine. However, when I try to implement the same in my own app, although I get no error I also get no notification.

我最初试图在主要活动中简单地创建一个测试对象,但是我想知道这是否与主从类型应用程序有关.

I'm initially trying to simply create a test one in the main activity but I am wondering if it has anything to do with this being a master-detail type app.

我是否必须给通知构建者和管理者不同的上下文,而不是如示例所示的主要活动?不幸的是,我没有找到实现通知的示例主从应用程序.

Do I have to give the notification builder and manager different contexts and not the main activity as the sample shows? Unfortunately I have not managed to find an example master-detail app implementing notifications.

主要活动OnCreate()如下...

The main activity OnCreate() is as follows...

    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
        AndroidContext = this;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);

        UserDialogs.Init(this);

        LoadApplication(new App()); //<- setup master-detail forms

        IsPlayServicesAvailable();

        FirebaseApp.InitializeApp(this);
        var refreshedToken = FirebaseInstanceId.Instance.Token;

        var notificationBuilder = new Notification.Builder(this)
                .SetSmallIcon(Resource.Drawable.icon)
                .SetContentTitle("myStaff Message")
                .SetContentText("test")
                .SetAutoCancel(true);

        var notificationManager = NotificationManager.FromContext(this);

        notificationManager.Notify(0, notificationBuilder.Build());            
    }

我能否请人们避免使用您应该使用xyz插件"或使用nuget abc ..."或类似内容进行回应.我很欣赏有很多可以做到这一点的插件,但我想了解我的代码出了什么问题,而不仅仅是避免/解决问题.

Could I please ask that people refrain from responding with "you should use xyz plugin" or "use nuget abc..." or similar. While I appreciate that there are plenty of plugins which can do this, I want to understand what is going wrong with my code and not simply avoid/workaround the problem.

好的,这比我意识到的要深.我现在也尝试使用两个不同的插件-两种情况下的结果相同,没有错误但没有通知.这只是坚果.打算在我的代码中返回几周,然后尝试在那里然后迭代到停止的位置(何时),也许这将为我提供阻止它的线索

Ok, so this goes deeper than I realised. I have now tried with two different plugins too - same result in both cases, no error but no notification. This is just nuts. Going to go back a few weeks in my code and try there then iterate in to where (when) it stops, perhaps that will give me a clue to what's blocking it

推荐答案

因此,在进一步调查并挖掘出较旧的设备后,这似乎是一个奥利奥问题.

So, upon further investigation and digging out older devices, it would appear that this is an Oreo issue.

似乎缺少官方文档,并且演示项目不允许使用Channels,这就是问题所在.它与主从细节无关-我的代码在较旧的设备上运行时(在所有版本上)都可以正常工作,而在8.0+上则不行-现在我只需要对其进行修复.

It appears that the official documentation is lacking and the demo projects do not allow for Channels and this is where the problem lies. It has nothing to do with master-detail - my code works just fine (all versions) when run on an older device, just not on 8.0+ - now I just have to fix it.

根据 kylewhittington 此github线程中的帖子(关于第8个帖子),我现在已经设法编写了一个适用于Oreo和旧版Android的解决方案.只需添加iOS的代码即可.

based on the post by kylewhittington in this github thread (about the 8th post) I have now managed to code a solution which works in both Oreo and older version of Android. Just have to add the code for iOS.

这篇关于在主从应用程序中显示通知-没有错误,但也没有通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆