local notification with ACR Notifications Plugin

SamoSSamoS ✭✭Member ✭✭

Hi all

I would like to generate the local notification. For this purpose, I used the ACR Notification Plugin which does not work in my case. In the first step I called
the request permission function (bool result = await CrossNotifications.Current.RequestPermission()) which always throws the true value. After that, I called

await CrossNotifications.Current.Send(new Notification
{
Title = "Samples",
Message = "Starting Sample Schedule Notifications",
Id = 5,

        });

which caused the following exception:
System.TypeInitializationException: The type initializer for 'Plugin.Notifications.AndroidConfig' threw an exception.
If anyone knows how to handle this exception or why this exception appears I will be grateful.

Thanks in advance.
Samo

Answers

  • batmacibatmaci ✭✭✭✭✭ DEMember ✭✭✭✭✭

    oh wow, this plugin didnt work for me last time also and i reported similar issues but owner is not easy person. he doesnt accept things and simply closes every issue. now i went back to its github and he even disabled issues :D this guy is epic but unfortunately his plugins are without alternative. let me know if you find an alternative.

  • JohnHardmanJohnHardman mod GBUniversity mod

    @batmaci said:
    unfortunately his plugins are without alternative. let me know if you find an alternative.

    There are alternatives, including the following two:
    https://github.com/edsnider/LocalNotificationsPlugin
    https://github.com/CrossGeeks/PushNotificationPlugin

    I started off by using the first of those, then migrated to the ACR plugin. I've since removed it and implemented my own notification handling based on what I've learnt from those, including exposing both synchronous and asynchronous methods. Whilst I do normally go for "async everywhere", I found with my use of notifications that I had a scenario that required a synchronous API.

  • batmacibatmaci ✭✭✭✭✭ DEMember ✭✭✭✭✭

    @JohnHardman said:

    @batmaci said:
    unfortunately his plugins are without alternative. let me know if you find an alternative.

    There are alternatives, including the following two:
    https://github.com/edsnider/LocalNotificationsPlugin
    https://github.com/CrossGeeks/PushNotificationPlugin

    I started off by using the first of those, then migrated to the ACR plugin. I've since removed it and implemented my own notification handling based on what I've learnt from those, including exposing both synchronous and asynchronous methods. Whilst I do normally go for "async everywhere", I found with my use of notifications that I had a scenario that required a synchronous API.

    i implemented also myself on Android on one of my old app 2 years ago. it was quite easy but i couldnt figure out on UWP. is it easy to implement on UWP and how about scheduling for a specific datetime?

  • JohnHardmanJohnHardman mod GBUniversity mod

    @batmaci said:
    is it easy to implement on UWP and how about scheduling for a specific datetime?

    Yes. The ACR plugin works well on UWP, so that's a good starting point if you want to adapt it in some way.

  • SamoSSamoS ✭✭ Member ✭✭

    I think that I know why the library does not work on my phone. The library does not support channels which are required in the case of Android 8.0. I will try to write the code on my own.

    JohnHardman: the first library has some limitations. For instance, if you click on notification the application is not resumed from the background but it is reopened which is not recommended in my case. The second one supports push notifications which are not the same as local notifications.

    Thanks for help guys.

  • SamoSSamoS ✭✭ Member ✭✭

    @SamoS said:
    I think that I know why the library does not work on my phone. The library does not support channels which are required in the case of Android 8.0.

    JohnHardman: the first library has some limitations. For instance, if you click on notification when the application is open it not resumes but it reopens (first close and then reopen). For notification, I wrote the following code:

    var notificationManager = (NotificationManager)GetSystemService(NotificationService) as NotificationManager;
    notificationManager.CreateNotificationChannel(channel);

            Intent intent = new Intent(this, typeof(MainActivity));
    
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent );
    
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this,CHANNEL_ID)
                                        .SetContentIntent(pendingIntent)
                                        .SetContentTitle(Title)
                                         .SetContentText(Content)                                         
                                        .SetSmallIcon(Resource.Drawable.notificationIcon);        
    

    but It seems that it does not work as I would like. If the app is open and you click on notification the app/MainActivity is reopened and not resumed though I set PendingIntentFlags.UpdateCurrent flag. I will be grateful for any hint.

    Thanks for help guys.

  • JohnHardmanJohnHardman mod GBUniversity mod
    edited October 2018

    @SamoS said:
    the first library has some limitations. For instance, if you click on notification the application is not resumed from the background but it is reopened which is not recommended in my case.

    True. Some care is required about state, resetting statics to their defaults, flushing cached data etc.

    If you find a way of getting it to resume, I'd be very interested to hear how. I have to admit that I haven't researched Android notification handling in depth, instead adapting existing plugins with as little change as possible. I'll look into it in more detail at some point, but it may be a while.

    Obviously, if the activity has already transitioned to the Destroyed state there is no option but to re-start. But if it's Stopped or Paused, it would be better to avoid going back through OnCreate.

    @batmaci - Is this something you managed to do in your Android code?

    @AllanRitchie - apologies for the tag - is this something you can advise on?

    @SamoS said:
    The second one supports push notifications which are not the same as local notifications.

    Ah, ok - as per my earlier post, I haven't used that one.

  • AllanRitchieAllanRitchie ✭✭✭ CAInsider, University ✭✭✭

    @JohnHardman As mentioned in our earlier discussion, I'm not working on this plugin right now. I disabled the issues on the repo because I don't want to deal with the support on it right now.

    @batmaci I'm difficult because I'm tired of being a support train for the community and its comments like this that make it that much harder to want to help anyone! If you worked in OSS and received over million downloads with 10-20 messages a day asking for something, trust me, you would have the same issue.

  • NMackayNMackay mod GBInsider, University mod

    @AllanRitchie said:
    @JohnHardman As mentioned in our earlier discussion, I'm not working on this plugin right now. I disabled the issues on the repo because I don't want to deal with the support on it right now.

    @batmaci I'm difficult because I'm tired of being a support train for the community and its comments like this that make it that much harder to want to help anyone! If you worked in OSS and received over million downloads with 10-20 messages a day asking for something, trust me, you would have the same issue.

    @AllanRitchie
    You should consider starting a Patroen page like prismlib did, I think you'd be surprised how people and companies that make use of your good work will pledge, totally understand you been hacked of with that comment.

  • JohnHardmanJohnHardman mod GBUniversity mod

    @NMackay said:
    @AllanRitchie
    You should consider starting a Patroen page like prismlib did, I think you'd be surprised how people and companies that make use of your good work will pledge, totally understand you been hacked of with that comment.

    I fully support paying for use of plugins that do something useful and that work reliably. Building functionality for one's own use takes time. Building it, publishing it and supporting it takes even more time (which is why I don't currently do it, but take my hat off to those who do). Whether using Patroen (which I hadn't heard of before), or having your own infrastructure as per MR.Gestures, both are good if they encourage people to create and publish useful plugins.

Sign In or Register to comment.