GithubHelp home page GithubHelp logo

Comments (5)

Deba22 avatar Deba22 commented on June 2, 2024 1

I was able to get it working by using the below code while registering for a foreground service:

String NOTIFICATION_CHANNEL_ID = "com.test.testapp";
               String channelName = "test app service";
               NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.ImportanceNone);
               chan.LockscreenVisibility = NotificationVisibility.Private;
               NotificationManager manager = (NotificationManager)GetSystemService(Context.NotificationService);
               manager.CreateNotificationChannel(chan);

               NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
               Notification notification = notificationBuilder.SetOngoing(true)
                       .SetSmallIcon(Resource.Drawable.ic_stat_name)
                       .SetContentTitle("App is running in background")
                       .SetPriority(1)
                       .SetCategory(Notification.CategoryService)
                       .Build();
              
               StartForeground(Constants.SERVICE_RUNNING_NOTIFICATION_ID, notification);

I hope this helps you.

from monodroid-samples.

Deba22 avatar Deba22 commented on June 2, 2024

@LeonSweden did you find a solution to this? even im facing the same issue. Please help!

from monodroid-samples.

amr-moomen avatar amr-moomen commented on June 2, 2024

I'm facing the same issue. any help!

from monodroid-samples.

tatapuchi avatar tatapuchi commented on June 2, 2024

NotificationManager.Importance none is obsolete and will be removed, use NotificationImportance.None instead

from monodroid-samples.

johnjore avatar johnjore commented on June 2, 2024

Combining the two posts above, this is my replacement (its half baked, and half implemented in my app, hence the namespace changes etc), but my app does not crash at startup anymore.

		void RegisterForegroundService()
		{
			String NOTIFICATION_CHANNEL_ID = "no.jore.hajk";
			String channelName = "test app service";
            NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationImportance.None)
            {
                LockscreenVisibility = NotificationVisibility.Private
            };
            NotificationManager manager = (NotificationManager)GetSystemService(Context.NotificationService);
			manager.CreateNotificationChannel(chan);

			NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
			Notification notification = notificationBuilder.SetOngoing(true)
					.SetSmallIcon(Resource.Drawable.route)
					.SetContentTitle(Resources.GetString(Resource.String.app_name))
					.SetContentText(Resources.GetString(Resource.String.notification_text))
					.SetContentIntent(BuildIntentToShowMainActivity())
					.SetPriority(1)
					.SetOngoing(true)
					.SetCategory(Notification.CategoryService)
					.AddAction(BuildStopServiceAction())
					.Build();

			// Enlist this instance of the service as a foreground service
			StartForeground(PrefsActivity.SERVICE_RUNNING_NOTIFICATION_ID, notification);
		}

Updating the sample to a working version would be nice

from monodroid-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.