Comments (5)
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.
@LeonSweden did you find a solution to this? even im facing the same issue. Please help!
from monodroid-samples.
I'm facing the same issue. any help!
from monodroid-samples.
NotificationManager.Importance none is obsolete and will be removed, use NotificationImportance.None instead
from monodroid-samples.
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)
- --closed---
- Missing permission
- Second hand skips quickly through 59th second
- GetExternalStorageDirectory is deprecated. HOT 1
- Not able to connect to the scanned devices
- PhotoAlbum.cs Resource.Drawable error
- error when building monodroid-samples/android5.0/Camera2VideoSample: Unknown flag -p HOT 1
- Unable to run hce nfc card emulation project on Samsung A51 android ver X
- Update mapsandlocationdemo-v3 to not use deprecated Android.App.Fragment HOT 23
- doigf HOT 1
- Foreground Service Demo doesn't work Anymore on Android 11 HOT 3
- Android 12 Splash Screen API update HOT 2
- Messenger Service Demo always fails ignoring service installed first
- AutofillFramework sample doesn't work with API version 30 HOT 1
- AutofillFramework sample's SettingsActivity FindViewById always returns null
- ForegroundServiceDemo crashes with null reference exception when clicking start service HOT 2
- Camera2VideoSample: Random crash with repeated Record/Preview
- Camera2Basic: images too bright with flash HOT 1
- San Angeles ndk demo cannot be loaded HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from monodroid-samples.