android


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.

Related Links

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?

Categories

HOME
uml
google-app-engine
google-cloud-platform
fuelux
socket.io
shiro
knitr
google-cloud-functions
entity-framework-core
alsa
big-o
maxscript
android-json
distribution
github-enterprise
ipmitool
jsonpath
php-5.6
speech-synthesis
zerobrane
entitymanager
google-data-studio
swagger-2.0
pagespeed
php-mysqlidb
jboss6.x
froala
expressionengine3
fable-f#
ms-access-web-app
browser-sync
finagle
nsurl
alm
r-grid
carriage-return
jwplayer6
magento-1.9.2.4
flatmap
ods
apns-php
c9.io
dynamic-linq
ntvs
term
sonarlint-eclipse
cnc
tinymce-3
manova
oracleclient
vibrate
branch-prediction
pocketsphinx-android
usart
ziparchive
latin
centrifuge
jclouds
appscale
nservicebus5
php-socket
data-protection
dbamp
lz77
dynamics-nav-2016
lazybones
ess
google-books
ocra
diff3
xmltype
code-documentation
nodelist
jbake
parallel-testing
lnk
grails-plugin-rabbitmq
paste
fpdi
qscrollarea
scriptaculous
cocoalibspotify-2.0
diem
apache-abdera
preload
dopostback
qi4j
entity-attribute-value
user-tracking
saxparseexception
winmain
drawtobitmap
cdonts
updatesourcetrigger
aspmenu
ajax-polling
application-verifier
pagemethods
cfwindow
echo3
build-environment
lobo-cobra
interop-domino
contentpresenter
pbcopy
wspbuilder

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App