Android Xamarin push notifications not working

I followed the instructions in the Xamarin Android setup and have:

airshipconfig.properties

google-services.json

airship dll

call takeoff in oncreate

  public override void OnCreate()
        {
            base.OnCreate();
         

            // Call takeOff
            UAirship.TakeOff(this, (UAirship airship) =>
            {
                airship.PushManager.UserNotificationsEnabled = true;
                airship.PushManager.Tags = new String[] { "android-xamarin" };
            });
            try
            {
                var channelid = UAirship.Shared().PushManager.ChannelId;
              
            }
            catch (Exception)
            {

            }

 

Under the audience tab in the dashboard I see some channels but they're all inactive.  I see no tokens

Didn't find what you were looking for?

New post

Comments

35 comments

  • Works now.  Honestly don't know what the difference is

    Comment actions Permalink
    0
  • Patrick,

    Sometimes there may be delays with regards to device registration, which could explain why your device was inactive. Until the registration info gets updated, it would remain inactive.

    But, good to hear its working now!

    Comment actions Permalink
    0
  • That's what I'm wondering.  It worked, now it doesn't again. I uninstalled the app and reinstalled it.  Shouldn't it be working now?  I have a breakpoint on OnChannelRegistrationSucceeded and it doesn't always get called.  Why is this?

    Comment actions Permalink
    0
  • Patrick,

    Could be any number of reasons, though usually it might be the device.

    Would you happen to have logcat logs from the Android device? That might shed some light on whats happening in the background for that app/device, and we can probably figure it out from there.

    Comment actions Permalink
    0
  • Sure how do I attach it?

     

    thanks

    Comment actions Permalink
    0
  • Patrick,

    I can send you a Box link to upload it. What would be a good email to send the invite to?

    Comment actions Permalink
    0
  • pgoode at blacklineconsulting dot com

    Comment actions Permalink
    0
  • Patrick,

    Seems like the invite was already sent! If you log into Box.com, you should be able to upload it in the existing folder.

    Comment actions Permalink
    0
  • Thanks.  I sent it

    Comment actions Permalink
    0
  • Patrick,

    Perfect.

    I saw this log line:

    "02-01 13:04:37.334 W/ActivityManager( 1407): Unable to start service Intent { act=com.urbanairship.push.ACTION_START_REGISTRATION cmp=craytondemo.Droid/com.urbanairship.AirshipService VirtualScreenParam=Params{mDisplayId=-1, null, mFlags=0x00000000)} (has extras) } U=0: not found"

    Given that the intent isn't firing, that's likely why your device is being registered as inactive.

    Now, why that event isn't firing is the other question.

    Out of curiosity, what is the MinSDK version you have set in your app, and are you implementing the sample from Github, or creating your own app from scratch?

    Comment actions Permalink
    0
  • These are the settings

     

    I didn't implement any intents.  I'm using the OnCreate like the sample app from the Xamarin UA download

     

    Comment actions Permalink
    0
  • Still strange that it would work and then not work.

    Comment actions Permalink
    0
  • This isn't android native, this is Xamarin Forms Android if that helps

    Comment actions Permalink
    0
  • Xamarin forms shouldn't change too much about the implementation, but it can depend on where you're calling takeOff().

    I'm assuming, though, that you're calling takeOff() from within the onCreate method inside your MainActivity.cs class, is that correct?

    Comment actions Permalink
    0
  • Inside MainApplication like this

     

      public class MainApplication : Android.App.Application, Android.App.Application.IActivityLifecycleCallbacks
        {
            public MainApplication(IntPtr handle, JniHandleOwnership transer)
              : base(handle, transer)
            {
            }

            public override void OnCreate()
            {
                base.OnCreate();
                RegisterActivityLifecycleCallbacks(this);
                //A great place to initialize Xamarin.Insights and Dependency Services!

                // Call takeOff
                UAirship.TakeOff(this, (UAirship airship) =>
                {
                    airship.PushManager.UserNotificationsEnabled = true;
                    airship.PushManager.Tags = new String[] { "android-xamarin" };
                });
                try
                {
                    var channelid = UAirship.Shared().PushManager.ChannelId;
                  
                }
                catch (Exception)
                {

                }

            }

            public override void OnTerminate()
            {
                base.OnTerminate();
                UnregisterActivityLifecycleCallbacks(this);
            }

            public void OnActivityCreated(Activity activity, Bundle savedInstanceState)
            {
             
            }

            public void OnActivityDestroyed(Activity activity)
            {
            }

            public void OnActivityPaused(Activity activity)
            {
            }

            public void OnActivityResumed(Activity activity)
            {
                 
            }

            public void OnActivitySaveInstanceState(Activity activity, Bundle outState)
            {
            }

            public void OnActivityStarted(Activity activity)
            {
               
            }

            public void OnActivityStopped(Activity activity)
            {
            }
        }

    Comment actions Permalink
    0
  • Is there any resolution to this?  I've got a lot of potential clients lining up to use this API

     

    thanks

    Comment actions Permalink
    0
  • Patrick,

    Try instead adding your Urban Airship code inside the MainActivity.cs class instead of the Application class. 

    If I'm correct, Xamarin Forms samples don't actually create the Application Class for you, instead they provide the MainActivity class.

    Also, please note, the forums here do not have resolution timers. 

    If you wish for a more speedy response, please consider upgrading your Support package on your account.

    Otherwise, we'll respond here when we can.

    Comment actions Permalink
    0
  • Ok.  Thank you very much for your responses.  We will certainly consider upgrading once we get a reliable proof of concept. 

    I tried adding the takeoff code in main activity like this:

     

     // Call takeOff
                UAirship.TakeOff(new Android.App.Application(), (UAirship airship) =>
                {
                    airship.PushManager.UserNotificationsEnabled = true;
                    airship.PushManager.Tags = new String[] { "android-xamarin" };
                });
                try
                {
                    var channelid = UAirship.Shared().PushManager.ChannelId;

                }
                catch (Exception)
                {

                }

                LoadApplication(new App());

     

    It throws an error:


    Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference

    Comment actions Permalink
    0
  • I'm curious as to how I have another app set up the exact same way and now I'm getting push notifications for that one.  Before I wasn't

    Comment actions Permalink
    0
  • Patrick,

    What are the App Keys for the two different apps you're testing on?

    I might be able to look at the feedback we're getting from GCM to see if there is anything weird going on with the device.

    Comment actions Permalink
    0
  • Ok sure

     

    Not working:  ZKUqPQkxQ46uobNC-vQIiQ

    Working:  zkkA0ApIQ0-AcdDl1QeoCA

     

    thank you,

    Comment actions Permalink
    0
  • Patrick,

    Just to be sure, you're not swapping the app keys in your airshipconfig.properties file, correct? You only have one pair of app keys in that file?

    Comment actions Permalink
    0
  • Correct, I double checked the keys in both apps.  One pair of keys per app.

    thanks

    Comment actions Permalink
    0
  • Patrick,

    Just to give you an update, I'm still gathering up some logs, however its taking a bit longer to complete than I expected. As soon as it completes, I'll dig through to see what I can find and report back.

    Comment actions Permalink
    0
  • Ok sounds great.  Thank you very much for your support!

    Comment actions Permalink
    0
  • Patrick,

    Well, I found the source of the problem from this log line:

    2017-02-01 18:25:48,927 - NotRegistered error, dropping send for app/apid/registration id (ZKUqPQkxQ46uobNC-vQIiQ/04d29a7e-0347-49e1-8f7e-47f6209df935/cHUgO2SlPbI:APA91bFqkb7_LKBi3whtXo0BaLelerNb2JH-lG_2Xt4vKqoE45HxACTXVpp_H4sr0_K7AvBkRDquflmo1Q081OIMsyfO6PIFuBi5-OIlgO8CARso28elxjjwKxGPQM5l4edmB91x-dM0)

    So, it appears we're getting feedback from GCM that that device is not registered for GCM.

    This could be due to the device being uninstalled, but I'm assuming you're not actually uninstalling and reinstalling the device during this endeavor, so that probably throws that out the window.

    Though, one thing I've noticed on some Android devices is that if the time/date is not updated correctly, that can cause some funky things to happen with regard to Google Play, which may affect registration.

    Do you know if your current test device has automatic date/time enabled? Or, have you been testing with multiple devices?

    Comment actions Permalink
    0
  • Hi,

    Yes I'm testing on two real devices, both with auto date/time enabled, as well as an emulator.  Once more, I'm doing the same thing with the app that works.

     

    thanks

    Comment actions Permalink
    0
  • Patrick,

    Could it be related to your GCM API Keys perhaps?

    If you wouldn't mind, try creating a new project in your Google Developer Console and creating a new GCM API Key and update that in your airshipconfig.properties file.

    Comment actions Permalink
    0
  • Certainly, will do

    Comment actions Permalink
    0
  • Ok, I created a new Google app, updated the settings in airshipconfig.properties, changed the properties in the UA gcm settings page.  Still no push notifications unfortunately.

    Comment actions Permalink
    0

Please sign in to leave a comment.