Android: OTG Storage notification conflicts with radio c
I am working on an ongoing service which listens for a USB interface connection to a radio. When such a connection is found, this service updates its notification to reflect said connectivity; when a connection is lost (such as through an unplug event, or the radio being turned off), this service will update its notification to reflect said dis-connectivity. This service also writes to a database when it detects a change, so other applications can utilize that information. This service works properly on USB ports which aren't configured for OTG storage. However, when a USB port with OTG storage enabled is used, I run into some issues where the service notification doesn't update properly, even though the database is being correctly written to. I believe this is because the radio I am connecting to also functions as a OTG storage device, and so once a connection with said radio is made, the OTG storage notification occurs, and I may be losing my notification context. Further, if disconnect from the radio before the OTG storage is able to properly mount, the service notification and database correctly update. For example, if I am currently connected to a radio and OTG storage has mounted, if I disconnect said radio, the OTG storage will unmount but my service notification will not reflect that change, even though I can see that in the database the change occured properly. I am running this on Android 4.0.4, and so I thought this issue was merely because my code was deprecated: import android.app.Notification; import android.app.Notification.Builder; import android.app.NotificationManager; import android.app.PendingIntent; Notification notification = new Notification(icon, contentTitle, time); notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); notification.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; notificationManager.notify(NOTIFICATION_ID, notification); But I still have issues when updating to Notification.Builder: Notification.Builder notiBuilder = new Notification.Builder(this); notiBuilder.setSmallIcon(icon); notiBuilder.setContentTitle(contentTitle); notiBuilder.setContentText(contentText); notiBuilder.setContentIntent(contentIntent); notiBuilder.setPriority(2); notificationManager.notify(NOTIFICATION_ID, notiBuilder.getNotification()); So I'm a little confused about what the issue might be. Please let me know if you have any ideas or suggestions, or if there's any code I should have included to be more helpful.
Update: Rather than being an issue with the actual notification, the issue turned out to be a race condition between the OTG storage and my service listening for the same unplug event. In order to workaround this issue, I made my service listen for the change in the OTG storage state. This seems to have resolved the issue, although is admittedly more of a workaround than anything.
Revert to MainActivity after pausing/exiting on SecondActivity
location.reload() causing cordova sqlite db to be locked
how to add android drm plugin
Last Accessed Time of any file in Android
Is it possible to make android library contains readme.txt?
Accelerometer RxJava Backpressure
ionic run android not work
Activity Transitions + ImageView (Android)
Switch or ToggleButton
Draw GoogleMap path with 9patch
Android View with same ActionBar elevation
android - How to build a new app inside the app
Image loader is not working
Changing the color of a button on click
Android: Use Google API for Real-time directions, or Communicate with Google Maps?
Automatically launching Android app or service when Bluetooth connection is made?