Forum Xamarin.Android

Notification is not sent when the phone is locked.

JassimRahmaJassimRahma USMember ✭✭✭✭
edited May 2018 in Xamarin.Android


I am using below code to send local notification but the notification is not being sent when the phone is locked.

How can I fix this please?

using System;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Xamarin.Forms.Platform.Android.AppLinks;
using Plugin.Permissions;
using Plugin.Permissions.Abstractions;
using Plugin.MediaManager;
using Plugin.MediaManager.Abstractions;
using System.Threading;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;
using Plugin.Geolocator;
using Plugin.Geolocator.Abstractions;
using Newtonsoft.Json;
using Android.Util;
using Android.Support.V7.AppCompat;
using System.IO;
using System.Net;
using System.Text;
using Android.Media;

namespace Jafaria.Droid
    public class PrayerTimes: Service
        public override IBinder OnBind(Intent intent)
            throw new NotImplementedException();

        private void SendNotification()
            global::Android.Net.Uri uri = global::Android.Net.Uri.Parse("android.resource://" + this.PackageName + "/Raw/" + Resource.Raw.AthanAffasi);

            Notification.Builder builder = new Notification.Builder(this)
                .SetContentTitle("حان الآن موعد أذان الفجر") 
                .SetVibrate(new long[] { 1000, 1000 })
                .SetContentText("نسألكم الدعاء");

            NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
            notificationManager.Notify(1000, builder.Build());

        private Timer _Check_timer_Data;
        public void DebugMyBGService()
            _Check_timer_Data = new Timer((o) => {
                Log.Debug("SS", "just a test");
            }, null, 0, 60000);

        [return: GeneratedEnum]
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
            Log.Debug("SS", "service now started");
            return StartCommandResult.NotSticky;

        public override bool StopService(Intent name)
            Log.Debug("SS", "service now stoped");
            return true;


Sign In or Register to comment.