New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notification.setLatestEventInfo() is removed in API Level 23 #290
Comments
Did you find a solution for that? |
@erick03 If you mean a solution for being able to update From my conversation here with Google on the best practice for updating notifications: Me:
Google:
So the solution is to implement the above, and test to make sure reminders still work correctly. It's on my TODO list, but I've been trying to focus on getting the UI redesign to the point of release. PR's accepted! :) |
We should also be using |
Great! |
Here's how notifications are currently used in OBA Android:
You should get a notification then based on the reminder you set up - for example, if you selected to be reminded 5 minutes before the Route 5 North arrives, when the Route 5 North prediction reaches 5 min you should get a notification. |
As far as unit-testing Notifications on Android - I've never set this up before, so I'm not sure the best way to approach it. Ideally it would involve actually registering a Notification and then retrieving it from the Android framework to confirm it was set up correctly, or somehow otherwise detecting it. The following seems promising - http://stackoverflow.com/a/34467347/937715. |
Ok, as far as my testing goes, the code I wrote using new notifications framework produces notifications properly. I just have to generate the test for it as required (I believe?) by the developer agreement. Should I also bump the compile sdk version as part of this fix, or will that be handled elsewhere? |
Cool! Tests aren't required, but very much appreciated. They help us keep the code quality high. Let's wait to bump |
The closest existing test would probably be the provider test for the reminders (trip alerts) - https://github.com/OneBusAway/onebusaway-android/blob/master/onebusaway-android/src/androidTest/java/org/onebusaway/android/provider/test/TripAlertsTest.java It just tests if the proper records are inserted in the provider, though, it doesn't touch the actual notifications. @charles-b-stb For notification unit tests you might want to check out https://developer.android.com/reference/android/service/notification/NotificationListenerService.html - it seems like you might be able to set up a listener to confirm that the notifications are properly registered with the platform. |
Sorry for being late on updating this. I realized while working on a test case that my first implementation was wrong as it left the service trying to manage references to notification objects. I will fix this before continuing to build a test case. |
@charles-b-stb No rush! I'd prefer a correct solution to a fast one, so take your time. |
@barbeau I am still processing the needed changes, but this is beginning to look like a fairly big deal. From what I am seeing in the code, it looks like most if not all of the code in TripService.java is obsolete given the new architecture from Google. We should not be saving notifications anywhere at all. I would just rewrite this whole process to rely on NotificationManager to handle notifications, but it appears there is some sort of contract with the service and external apps. Is this correct? If so I will need to implement while maintaining these action flags. |
Yes, that's the best solution -
Yes, OBA was initially set up to be able to expose info to other apps (before my time), but to my knowledge this was never actually implemented by any other application. I started looking at this in #104 (comment) as part of troubleshooting #104, and found some potential problems with the implementation - see #104 (comment) and CUTR-at-USF@54b3e4c. I ended up backing away from some of these changes, as I found out these issues weren't the cause of #104 (the main cause was a bug in Android). So the above commit never made it into the master branch. You may be able to use that commit, though, in your current changes. I'd like to keep the current contract with the service and external apps if at all possible, as long as it works with the update Notification best practices and we resolve any known issues. |
… the new notification network that no longer stores notification objects locally.
I believe I have a viable fix here: https://github.com/charles-b-stb/onebusaway-android.git on the branch "issue290-NotificationManager". As far as my manual testing goes, this seems to be working, but I am still unclear on how to write a test case. The sample you shared earlier relies on an existing test framework set up specifically for provider objects, and its not clear to me that this will work with Notifications. At least, I do not see a mechanism for mocking notifications in the android test toolkit. Is it possible to write a test that directly interfaces with the notification manager, or does that need to be mocked somehow to make a test case work? |
Cool! As far as using native Android to implement the notifications test, I'd check out the In theory I think in a unit test you could set up the listener, register the notification, and make sure that your listener gets the same thing back that you registered. Main catches, from a quick read:
|
Conceptually, I understand what needs to be done to see if this will work. I'm a bit more fuzzy on the details for modifying the gradle scripts for allowing a 2nd (test only) manifest and how the service will interact with tests. Just to make sure I know what I'm doing here, are you implying that all debug versions of the build in onebusaway-android-onebusaway-android.iml should have their MANIFEST_FILE_RELATIVE_PATH changed to something like "/src/debug/AndroidManifest.xml" wherein a copy of the manifest referencing the notificaction service would reside? I presume that subsequently I would create a subclass of the NotificationListenerService which would listen for a specific notification I would create in a separate AndroidTestCase object. At that point (since these are not directly communicating) how would I verify the test completed? Would it be sufficient for the listener to report somewhere how many notifications it witnessed, or is some sort of timeout required to present a fail condition? |
It's been a little while since I worked on the Gradle build variants, but IIRC you should be able to drop a new file
I believe this should automatically merge the above attributes with the main You definitely shouldn't need to modify the
I'm not completely sure about this - it would require some testing. I'm not sure we have any other asynchronous tests in OBA Android. I think you're heading down the right path - you'd likely need to register the notification and then sleep for a second, and then check a class member variable to see if the subclass of NotificationListenerService received a callback indicating that the notification was correctly created. In the subclass of NotificationListenerService you'd set this class member variable to |
I am having issues getting the manifest version to cooperate. Apparently we need to be as high as version 23 in the manifest to use the NotificationListener. I've tried changing the version for the local manifest in the test folder, but it still apparently keeps referring to the version in the core manifest. Do you know of any workarounds to get past this? |
@charles-b-stb Did you try bumping You'll need to sync Android Studio with When you use
|
The only way I could find to get rid of the compiler error was to set the test notification listener implementation (which has to be referenced from the test manifest) to have an annotated version of 23 (@TargetApi(23)) unfortunately I don't know of a way to certify that lower versions of android cannot access this class since its will be instantiated from the manifest directly. I suspect that this method of test generation may cause crashes. If I am reading this correctly, since the class itself is instantiated from the manifest, it seems that surrounding the test code itself (which will only exercise our notification code) with a version check if statement will not prevent crashes. Am I reading this correctly, or is there something I am missing? I am beginning to wonder if this particular test is really feasible given android's current architecture. |
Yes, adding @TargetApi(23) to method is fine. This along with IF statement should be sufficient to run test only on M devices/emulators. |
@charles-b-stb If the test is proving difficult to implement, I'd be ok with you submitting a PR for the fix without it. For this particular case, I don't want perfect to be the enemy of good. This issue is blocking us bumping |
…oid version from being bumped. OneBusAway#290
… the new notification network that no longer stores notification objects locally.
… the new notification network that no longer stores notification objects locally. Removed unused deprecated method that was preventing the maximum android version from being bumped. OneBusAway#290
master
branchIf we update
compileSdkVersion
to23
, it no longer builds:Notification.setLatestEventInfo()
has been deprecated for a while, and has caused problems in the past (see #104).We should finally remove it.
The text was updated successfully, but these errors were encountered: