In Codename One, can I badge an android application icon? - android

I would like to have number badges on my application Icon set with a LocalNotification (ie: how many items are still unread in the app after the last session). I set a local notification to test this behavior using the following code and on Android, all I get is a top-bar notification with the number 10 in it, but no badge:
LocalNotification n = new LocalNotification();
n.setId("updatedLearnableCountBadge");
n.setBadgeNumber(10);
Display.getInstance().scheduleLocalNotification(
n,
System.currentTimeMillis() + 1000, // fire date/time
LocalNotification.REPEAT_NONE // Whether to repeat and what frequency
);
Is Badging on Android not implemented yet, or am I doing something wrong?
LocalNotificaiton doesn't mention any special conditions required to make the "setBadgeNumber" display properly, but are there some undocumented platform-specific conventions I'm not following here?

As far as I know Android itself doesn't support badging. It's a feature of iOS which we exposed due to user requirement but it can't be implemented outside of iOS to my knowledge.

Related

What is the exact purpose of the Android Notification Category? Specifically CATEGORY_WORKOUT?

Android Api level 31 introduces 2 new Categories CATEGORY_WORKOUT, CATEGORY_STOPWATCH. I tried to find a detailed information about those but nothing detailed is documented.
https://developer.android.com/reference/android/app/Notification
Is there any advantage of using those for a workout or stopwatch application? earlier I was using Category Progress which is claimed to keep as long running task. I suppose that Android gives it priority.
These categories are for ongoing notifications either on your phone or on a WearOS device.
The category will help the OS prioritize the importance of the notification.
There is an example of the usage in this Edge Wear OS ongoing activity walkthrough: https://developer.android.com/codelabs/ongoing-activity

Notification limit dropped to 24 per app in Android 11 notification drawer

Is there any limit on the number of notifications the android app can display? I am facing an issue after 24 notifications android notification does not appear.
There is no documentation which states this clearly.
This issue I have observed in Android 11. Looks like this is applicable to android 10 (https://support.google.com/pixelphone/thread/23619509?hl=en). I don't have android 10. So, I have not tested.
Please help me to get a documentation reference for this limit or this behavior can be changed using the settings of the device.
Yes, there is a limit of notifications that can be posted per app. The interesting thing was the number is not fixed and can be controlled by the Device Manufacturer. From my observation, a Google Pixel 3A phone had limited to 25 notifications were as an OnePlus 6T and a Samsung device had limited the notifications to 50.
If we carefully observe the NotificationManagerService.java source code, we can see a variable MAX_PACKAGE_COUNT declared to be 50.
And inside the code, it checks if the count is greater than the MAX_PACKAGE_NOTIFICATIONS, it has a message saying that “Package has. already posted max toasts. Not showing more!”
This is the reason we get limited by the number of notifications that are posted per app.
The number of notifications for a particular application has been set to 50 which is a default value set in notification manager. But more on that, the device manufacturer can also set this limit on their own.
Problem : Now the problem is that we can not change this number as it is not accessible to us or even visible.
Solution : If we want that our application delivers notifications continuously, we need to change a little bit of code in our application.
We have to clear the previous notifications which are not needed.
For that we can set Notification.builder.
NotificationCompat.Builder builder = new NotificationCompat.Builder(...);
builder.setContentTitle(...);
builder.setContentText(...);
builder.setTimeoutAfter(5000);
builder.setTimeoutAfter(5000);
The above line will auto-clear notifications after 5 seconds of notification arrival.
So newer notifications can be pushed by your application.
References : 1. Notification builder
2. builder.setTimeOutAfter();

Is it possible without react-native to gather geolocation information in a background task for Android and/or iOS?

Is it possible in react-native to execute a background task with monitoring GPS position (without running the whole app in the background), even if the phone is locked?
I want to show some information (notification) onscreen when the phone will be in some position.
I need to declare the subject of a project in my studies, but I don't know if it's possible to implement this functionality.
It most certainly is... if you have only one given position (Or fewer than 20 positions) what you'd be best using is CoreLocation's geofencing APIs!
You can set up a region like so:
if CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) {
// Register the region.
let region = CLCircularRegion(
center: center,
radius: maxDistance, identifier: identifier
)
region.notifyOnEntry = true
locationManager.startMonitoring(for: region)
}
(Assuming you have already requested and checked the user's location permissions)!
Your app will then get launched in the background whenever a region monitoring event occurs, so you must make sure to setup a new CLLocationManager and give it a delegate to receive the updates in your application(_application:didFinishLaunchingWithOptions) function!
You can then use the delegate callbacks to trigger a local notification.
There is a slight caveat here, that this won't work if the user has disabled background app refresh for your app!
Luck, there's already a react-native library that allows you to setup these regions: https://github.com/martijndeh/react-native-region-monitor. Unfortunately I do think it will launch your JavaScript app fully (in the background of course) when a notification comes through, but that's not too big an issue.
There may also be info on the GitHub provided for how to implement this on Android too!

How to properly update notification channel android oreo

I'm trying to update a notification channel after I create it. Namely, I want to properly set the notification sound, but after I create it. I can't really figure out the proper way to do this.
What I tried was to delete the channel and re-create it but it doesn't seem to be working...
if (notificationManager != null) {
notificationManager.deleteNotificationChannel(NOTIFICATION_CHANNEL_ID);
notificationManager.createNotificationChannel(channel);
System.out.println("Created notification channel" + channel.getSound() + " " + channel.getImportance());
}
It is correct like stated in the other answer that you can only alter the name and description of the channel once it has been created. However, as you point out in your code you can delete the channel and then create it again. But if you create the same channel once again but change something, for example the sound, it wont work. I'm assuming Android is preventing that change the same way it does if you try to create it when it already exists. So Android must have a way of keeping track of all the deleted channels (in other words, they are not completely deleted).
If you look at WhatsApp they allow you do change the sounds from within the app and if you investigate a little you'll find that they are indeed deleting and creating channels.
So what can you do? What you can do is that you can alter the ID of the new notification channel. Perhaps adding a big enough random element would prevent you from ever having the same ID twice. Or increment something and store that information within your app (prefs or db or something). If the "recreated" channel has a new ID Android will accept your "changes". Since you're not altering an existing channel, you're creating a completely new one. And if you keep the rest of the user-visible information intact (such as name, description etc) then the user will not notice this but only experience that the sound of that type of notification (channel) was altered from within the app.
Any downsides? Well, a superminor one is that Android will show in the App notification settings how many times a channel has been deleted (to alert the user of "spamming"). I don't think many users care about that. And you're also deviating from the design that Android wants (full user control of the channels) which perhaps might not be desirable.
So from how you describe your usecase I think it's fair to do it this way to accomplish what you want :)
Once a notification channel is created, the user has ultimate control over its settings. As the developer, you can only change the channel's title and description. If you want to recreate the channel, you have to use a different id.
See: https://developer.android.com/training/notify-user/channels

How to test vibration function in android?

I am writing a simple Phonegap application for Android. This program will send notification to notification bar and make the phone vibrate periodically.
I use navigator.notification.vibrate(time_period) to achieve the target. According to this article, both beep and vibration are not supported by android emulator. Hence, I was expecting that there could be entry indicating failure of it in the Catlog, but there is no such entry. The question is how to make sure that a vibration event has happened or failed (without deploying to a device).
AppHarbor looks like one of the ways to debug Phonegap application remotely. I wonder if there is other local ways to test Phonegap application as an HTML5 website in a Chrome browser (navigator.notification call is a standard call)? If yes, then it is probably possible to somehow parse the browser's console automatically to find out if the vibration event has happened.
Can you hide the vibrate() call behind an abstraction which you can replace depending on which platform you are using?
For example
var vibrateFunc = function(time_period) {
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
console.log('vibrating for ' + time_period)
} else {
navigator.notification.vibrate(time_period)
}
}
and then have your app code call vibrateFunc() whenever it wants to vibrate.

Categories

Resources