rdelrosario / xamarin-plugins

Cross platform Xamarin & Windows plugins for PCLs
MIT License
178 stars 161 forks source link

Android project is not compiling #107

Closed claudioredi closed 7 years ago

claudioredi commented 7 years ago

On line 254 for PushNotificationGcmListener you have

 resultPendingIntent.SetAction($"{currentMillis}");

Problem is that SetAction is not recognized as a valid method for PendingIntent.

Acilec commented 7 years ago

Having the same problem! Did you solve this?

claudioredi commented 7 years ago

@Acilec: I have forked and fixed the component https://github.com/FishAngler/xamarin-plugins

Please let me know how it goes.

Acilec commented 7 years ago

Hi Claudio!

Thank you very much for your reply!

I tried your fork but still got the same problem =(

What can I have done wrong? I went to the link you sent. Pressed Clone or download. Downloaded the zip and compiled it. Then I copied the new Plugin.dll and Plugin.Abstractions.dll to the old Nuget directory (replacing all).

Or is it something wrong with my implementation?

Regards

Fredrik


Från: Claudio Redi notifications@github.com Skickat: den 17 februari 2017 04:04 Till: rdelrosario/xamarin-plugins Kopia: Acilec; Mention Ämne: Re: [rdelrosario/xamarin-plugins] Android project is not compiling (#107)

@Acilechttps://github.com/Acilec: I have forked and fixed the component https://github.com/FishAngler/xamarin-plugins

Please let me know how it goes.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/rdelrosario/xamarin-plugins/issues/107#issuecomment-280545175, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AYoEpD9F1ee_lgvgmqEAW0dtHAf-6CnTks5rdRxDgaJpZM4LsNZz.

claudioredi commented 7 years ago

Acilec, not following :( you say you were able to compile and copy dlls... then It can't be the same error, my error was at compilation time.

Acilec commented 7 years ago

Hi!

Ok! Sorry, I posted two different replies on the same plugin and I thought you replied on the other one :\

Yes it compiles without any problem with your fork! Very good! =)

Do you have any idea why I get "Object reference not set to an instance of an object" in pushNotification.Plugin.PushNotificationGcmListener.OnMessageReceived

"CrossPushNotification.PushNotificationListener" is null and therefore crasches on "CrossPushNotification.PushNotificationListener.OnMessage(values, DeviceType.Android);"

Regards Fredrik


Från: Claudio Redi notifications@github.com Skickat: den 21 februari 2017 01:42 Till: rdelrosario/xamarin-plugins Kopia: Acilec; Mention Ämne: Re: [rdelrosario/xamarin-plugins] Android project is not compiling (#107)

Acilec, not following :( you say you were able to compile and copy dlls... then It can't be the same error, my error was at compilation time.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/rdelrosario/xamarin-plugins/issues/107#issuecomment-281221676, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AYoEpAiV9hhKCrGFSePJ6_1TEdTsG9bxks5rekD-gaJpZM4LsNZz.

claudioredi commented 7 years ago

Can you show your initialization logic? It may be possible you didn't initialized plugin

On the Android Application class, is better to use the OnCreate of the Android Application class so you can handle push notifications even when activities are closed or app not running by using our PushNotificationService to keep listening to push notifications.

CrossPushNotification.Initialize<CrossPushNotificationListener>("<ANDROID SENDER ID>");

Acilec commented 7 years ago

Here it is:

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity { public static Context AppContext;

protected override void OnCreate(Bundle bundle) { try { base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle);

            AppContext = this.ApplicationContext;

            System.Diagnostics.Debug.WriteLine("MainActivity OnCreate");

            //Should specify android Sender Id as parameter
            CrossPushNotification.Initialize<CrossPushNotificationListener>("xxxxxxxxxxxx");

            LoadApplication(new Portable.App());

            //This service will keep your app receiving push even when closed.
            StartPushService();
    }
    catch{}

} ...

Maybe the problem is that I'm not using the example code for the plugin with Application. Instead, I'm using the MainActivity that Xamarin created. Don't know how to implement the global::Xamarin.Forms.Forms.Init(this, bundle); and LoadApplication(new Portable.App());

in the plugin example code:

[Application] public class YourAndroidApplication : Application { public static Context AppContext;

public YourAndroidApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { } public override void OnCreate() { base.OnCreate();

AppContext = this.ApplicationContext;

 //TODO: Initialize CrossPushNotification Plugin
 //TODO: Replace string parameter with your Android SENDER ID
 //TODO: Specify the listener class implementing IPushNotificationListener interface in the Initialize generic
 CrossPushNotification.Initialize<CrossPushNotificationListener>("<ANDROID SENDER ID>");

 //This service will keep your app receiving push even when closed.
 StartPushService();

}

What do you think?

Regards

Fredrik


Från: Claudio Redi notifications@github.com Skickat: den 21 februari 2017 12:59 Till: rdelrosario/xamarin-plugins Kopia: Acilec; Mention Ämne: Re: [rdelrosario/xamarin-plugins] Android project is not compiling (#107)

Can you show your initialization logic? It may be possible you didn't initialized plugin

On the Android Application class, is better to use the OnCreate of the Android Application class so you can handle push notifications even when activities are closed or app not running by using our PushNotificationService to keep listening to push notifications.

CrossPushNotification.Initialize("");

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/rdelrosario/xamarin-plugins/issues/107#issuecomment-281337687, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AYoEpLImB_mSPqo87JOVw-7G5_lTg7hrks5ret-lgaJpZM4LsNZz.

claudioredi commented 7 years ago

Forgot to answer here, sorry! My recommendation is to debug and see if initialization is executed. Then follow plugin code to see if PushNotificationListener is set. It sounds listener should be set... but debug should reveal the truth