Skip to main content

Posts

Showing posts from 2017

send push notification from C# using FCM

        public bool SendPushNotification(string deviceId, string message)         {      //applicationID = "AIzaSyxxxxxxxxxxxxxxxxxxx"     // senderId = "98xxxxxxxxx"             bool isSent = false;             string str = "";             try             {                 WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");                 tRequest.Method = "post";                 tRequest.ContentType = "application/json";                 var data = new                 {                     to = deviceId,                     notification = new                     {                         body = message,                         title = "SpAlert",                         sound = "Enabled"                     }                 };                 var serializer = new JavaScriptSerializer();                 var json = serializer.Serialize(data);            

Push Notifications in Xamarin Forms

Step by step guide: 1) In your shared project, create an Interface called IPushNotificationRegister public interface IPushNotificationRegister {     void ExtractTokenAndRegister(); } This interface is used for fetching the push token and then send it to the server. this Token is unique per device. 2) In Your shared proejct, you should invoke ExtractTokenAndRegister (using your favourite IOC, I called it right after login). Android Implementation: 3) Add Receivers for listening to events received by Google GCM service: a) [BroadcastReceiver] [IntentFilter(new[] { Intent.ActionBootCompleted })] public class GCMBootReceiver : BroadcastReceiver {     public override void OnReceive(Context context, Intent intent)     {         MyIntentService.RunIntentInService(context, intent);         SetResult(Result.Ok, null, null);     } } b) [assembly: Permission(Name = "@PACKAGE_NAME@.permission.C2D_MESSAGE")] [assembly: UsesPermission(Name = "android.permission.WAKE_LOCK")] [ass