0

I have a requirement where i have to get data from usb of my android mobile which is connected to a gps device,the data should be recursively available whenever any application of mine ask it for.

Something like this should work as Location listener.

What can i use in android such that this requirement of getting data any time from this usb to an application is possible.

RShenoy
  • 25
  • 7

1 Answers1

0

this is inter process communication. the main method for IPC in android is to use services, see https://developers.android.com/guide/components/processes-and-threads.html#IPC

https://developers.android.com/guide/components/bound-services.html#Binding

you can run Service or IntentService in background and then bind (bindService()) or unbind (unbindService()) to the service when you need the GPS location

an example to use the internal GPS in background using the android system [!] service LocationListener is in http://www.stackoverflow.com/questions/28535703/best-way-to-get-user-gps-location-in-background-in-android

you have to do this differently because your service is not a system service

so write a background GPS service (this is what google says is best practice, i would use Service instead of IntentService -> https://developers.android.com/training/best-background.html) then your (self-written) applications can bind to the GPS service to get the data. You have to start the service in some app or at boot up

a very good binding example is http://www.stackoverflow.com/questions/4300291/example-communication-between-activity-and-service-using-messaging

normally external GPS implement USB CDC class so you should see it in /dev/tty(USB | ACM ,...) this is how you can communicate with it or you check if it has events in /dev/input/eventx (need root for this)

ralf htp
  • 9,149
  • 4
  • 22
  • 34
  • Thanks i will try this and get back to you.I am using a API from D2xx [link](https://github.com/ksksue/Android-FTDI-UART-Sample).Reference[link](http://www.ftdichip.com/Android.htm) to get data from USB,is there any example of android project to read data from usb. – RShenoy Jan 31 '17 at 07:43
  • depends on what USB class the extern GPS implements . if it implements CDC you can use serial port commands or capture the events or .... android lower-level usb is in `android.hardware.usb.UsbDeviceConnection `. examples are in https://developer.android.com/reference/android/hardware/usb/UsbDeviceConnection.html and http://www.programcreek.com/java-api-examples/index.php?api=android.hardware.usb.UsbDeviceConnection – ralf htp Jan 31 '17 at 10:42
  • the example is of "how to send messages between an activity and a service" i want to run my own service say 'A' separately(which receives data from usb) and get this data from this service 'A' to another or different applications.Please help me with this as well. – RShenoy Feb 05 '17 at 10:38
  • does not matter. you can bind from any application to the service you want, services are not explicitly bound to a particular application http://stackoverflow.com/questions/8341667/bind-unbind-service-example-android – ralf htp Feb 05 '17 at 15:08
  • i have done as per [http://stackoverflow.com/questions/4300291/example-communication-between-activity-and-service-using-messaging] and also refereed [http://stackoverflow.com/questions/8341667/bind-unbind-service-example-android] sorry to say but i am still not able to figure out how to subscribe and communicate with an service.Please help me with 'how to subscribe a service to from another external application – RShenoy Feb 06 '17 at 09:39
  • maybe see http://www.stackoverflow.com/questions/13745779/binding-to-a-service-from-another-app or ask a new question because i do also not know exactly how this is done (never used this...) http://www.stackoverflow.com/questions/16135157/how-to-start-service-using-external-intent – ralf htp Feb 06 '17 at 10:49