Add your service and use the ServerSocket class to listen for and act on incoming connections. However, do not call ServerSocket.accept() in the UI thread. This will cause your application to not respond. Instead, create a new thread, or depending on your actual scenario, perhaps AsyncTask .
source share