I should start by saying that I'm not (yet) an Android developer. I've got a very specific, personal task that I'd like to achieve. If what I want to do is possible then it will be worth me learning enough to make it work. If it's impossible then I'll stick to what I already know!
I have type 1 diabetes and use a medical app which displays my blood glucose level on an Android phone's lock screen. There's a screenshot below. I'd like to be able to capture the information (particularly the number in the red box) and use it in other ways.
I've tested another app that reads Android notifications, but it only seems to have access to the popup messages that appear from an app. It doesn't see the persistent notifications on the lock screen.
So... is it possible for an app to read those lock screen notifications?
Thanks in advance for your help.
Yes that is possible with NotificationListener:
https://developer.android.com/about/versions/android-4.3.html#NotificationListener
The flags FLAG_ONGOING_EVENT or FLAG_NO_CLEAR will let you know if a certain notification is persistent.
Here is a sample project that I found useful demonstrating NotificationListener. In the NotificationListenerExampleService.java, you can simply change the onNotificationPosted method to find out if a notification is persistent:
#Override
public void onNotificationPosted(StatusBarNotification sbn){
if (sbn.getPackageName().equals("package name of your desired app")) {
if (!sbn.isClearable()) {
Notification notif = sbn.getNotification();
// get your desired data in the notif object
}
}
}
Note that you can see the package name of an app by just simply going into its Google Play store page, and in the url you will find something like this:
https://play.google.com/store/apps/details?id=chat.rocket.ne2.reactnative&hl=en_CA
where the id field (chat.rocket.ne2.reactnative) is the package name.
Related
I am making a System which uses Bluetooth. But Bixby does not have Bluetooth API. So My plan was using Android Application and it catches notification then, send data by BlueTooth. But I recognize there is no Notification API in Bixby too.
So... Is there any idea to make a notification push by Bixby?
This feature is rather advanced. Here are some information that might help you.
Bixby is not allowed to edit contact or calendar other than using the already existing built-in capsule. Utterance example "add a meeting at 2 pm" would work fine already. There is no standard library for that.
If by "notification" you mean the pop up notification, there is a way to do so, but not directly from Bixby. The notification is an Android App notification that must sent by Android App. For example, let's call it MyEventApp and say you also have a MyCapsule. It is possible in MyCapsule using a deep link to request MyEventApp for a certain action (in this case, send notification or maybe schedule one)
For how to use deep link in Bixby please read https://bixbydevelopers.com/dev/docs/reference/type/result-view.app-launch as a starting point. There is also a github sample capsule.
The format for deep link (the payload-uri key in Bixby) depends on the MyEventApp and it's part of developer's responsibility to get the format correctly.
Please read carefully regarding https://bixbydevelopers.com/dev/docs/dev-guide/design-guides/design-principles.app-punch-out-policies Or your capsule submission might be rejected.
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
I want to add a mark as read option to the pull down notification bar of Gmail but I don't have the slightest clue about where to start. If somebody can tell me how to do it or point me in the direction of the right docs to pull it off it would be much appreciated.
I know it is possible because it has already been done, but I want to do it by myself.
That's quite an undertaking.
So the link you provided has a bit of a walkthrough in its description about where to start. The trick is that because you're trying to program a notification service for an EXISTING app, you don't really have control over the notifications the app itself creates. I suspect what you're going to have to do is program a NotificationListenerService, listen for gmail notifications, and somehow cancel the gmail notification and replace it with one of your own, as created through the android documentation.
For a good example of how NotificationListenerService works please take a look at this:
https://github.com/kpbird/NotificationListenerService-Example
The canceling is something I have not tested but you asked for ideas, not code. NotificationListenerService has a method cancelNotification(String pkg, String tag, int id) which looks like you can use to cancel the gmail notification.
You can get access to the raw Notification-object using an AccessibilityService. I haven't tried it before to be honest, but I assume you can modify the Notification and add your own buttons, etc.
More information on tinkering with the Notification-object in an AccessibilityService here: https://stackoverflow.com/a/10303676/198996
How to check if intent or app has started ?
My use case is I am showing up notifications through my app and I want to clear them all via myBuilder.cancelAll() if default messaging app has started since my app shows sms notifications. So I am kind of looking for something like:
if (smsAppStarted) {
myBuilder.cancelAll();
}
Thanks
To check if an app has started:
Get the package name of the sms app you want to check.
Then refer to my answer here:
Android how to know an app has been started and range apps priority according the starting times
By using that code, the list taskInfo will contain the list of all apps currently running. Search that list using the package name of the sms app. If it is present in that list, it means that that app has started and currently running.
If I get you right, you need to determine, if another app is currently running. If so, then use this solution.
Is it possible to programatically access the text posted on the android notification area (displayed by an application which is not my own)?
The logic I am after would be something like...
for each (NotificationMessage m in NotificationArea.Notifications)
{
String msg = m.GetMessage()
}
Unfortunately, no. This would create security concerns, possibly hijacking personal information. See This Thread
In Android 4.3 and above, use the NotificationListenerService. Otherwise use Accessibility.
http://developer.android.com/reference/android/service/notification/NotificationListenerService.html
This is possible with the accessibility service, but you have to pick up on notifications as they arrive (ie there isn't a list you can iterate around at any point). You'd need to build that up yourself.