Questions tagged [android-networking]

The Android networking subsystem. Use this tag for the Android-specific network programming only.

The Android networking subsystem. Use this tag for the Android programming side of networking only.

The official introduction provides a good overview over the Android-specific network programming concepts.

924 questions
2708
votes
64 answers

How can I fix 'android.os.NetworkOnMainThreadException'?

I got an error while running my Android project for RssReader. Code: URL url = new URL(urlToRssFeed); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader xmlreader =…
bejoy george
  • 29,385
  • 5
  • 19
  • 15
719
votes
64 answers

How to check internet access on Android? InetAddress never times out

I got a AsyncTask that is supposed to check the network access to a host name. But the doInBackground() is never timed out. Anyone have a clue? public class HostAvailabilityTask extends AsyncTask { private Main main; …
Vidar Vestnes
  • 42,644
  • 28
  • 86
  • 100
596
votes
10 answers

Comparison of Android networking libraries: OkHTTP, Retrofit, and Volley

Two-part question from an iOS developer learning Android, working on an Android project that will make a variety of requests from JSON to image to streaming download of audio and video: On iOS I have used the AFNetworking project extensively. Is…
Alfie Hanssen
  • 16,964
  • 12
  • 68
  • 74
275
votes
20 answers

Android check internet connection

I want to create an app that uses the internet and I'm trying to create a function that checks if a connection is available and if it isn't, go to an activity that has a retry button and an explanation. Attached is my code so far, but I'm getting…
iamlukeyb
  • 6,487
  • 12
  • 29
  • 40
273
votes
21 answers

Broadcast receiver for checking internet connection in android app

I am developing an Android broadcast receiver for checking the internet connection. The problem is that my broadcast receiver is being called two times. I want it to get called only when the network is available. If it is unavailable, I don't want…
Nikhil Agrawal
  • 26,128
  • 21
  • 90
  • 126
150
votes
8 answers

Trusting all certificates with okHttp

For testing purposes, I'm trying to add a socket factory to my okHttp client that trusts everything while a proxy is set. This has been done many times over, but my implementation of a trusting socket factory seems to be missing something: class…
seato
  • 2,061
  • 2
  • 15
  • 18
121
votes
3 answers

Get response status code using Retrofit 2.0 and RxJava

I'm trying to upgrade to Retrofit 2.0 and add RxJava in my android project. I'm making an api call and want to retrieve the error code in case of an error response from the server. Observable apiCall(@Body body); And in the…
A.B.
  • 1,441
  • 3
  • 12
  • 10
121
votes
19 answers

Volley Android Networking Library

I have few questions around using Volley in my projects: Can this library be used in any Java project or just Android? I see multiple branches here and no documentation on which branch is to start with. Which branch should I use to start with? How…
bianca
  • 7,004
  • 12
  • 43
  • 58
75
votes
6 answers

How to determine if network type is 2G, 3G or 4G

I have an indicator on my application to display the network type (2G or 3G or 4G) but after getting the network type, how do I know what speed category it should be in? I know how to detect the network type: private TelephonyManager…
Tary
  • 1,021
  • 1
  • 10
  • 13
61
votes
4 answers

Network listener Android

I want to check when the network of phone in Android goes off. Can I capture that event? I am not getting the proper API or any example which would explain the same. If anyone had done or any example links would be really helpful.
Sam97305421562
  • 3,027
  • 10
  • 35
  • 45
49
votes
4 answers

Volley and AsyncTask

I read a post about Volley and I know it's great networking library. But I couldn't understand one thing. All requests are Async Task or not? When I want to send asyncTask request using Volley do I need put Volley request in AsyncTask? or should I…
pmb
  • 2,327
  • 3
  • 30
  • 47
48
votes
9 answers

Get my wifi ip address Android

How can I get the ip address of my phone when it is connected under wifi? I found a method here but it returns something like 24.182.239.255 even if I'm under wifi and I expect something like 192.168.1.10. I'd like something like: if (you are under…
Luigi Tiburzi
  • 4,265
  • 7
  • 32
  • 43
43
votes
1 answer

Workaround mapping between NetworkInfo and NetworkInterface

I'm facing an issue that was reported in this tracker issue back in 2011 and would like to develop a suitable workaround. I would like to display all of an Android device's network interfaces to the user, as well as categorize them by their type and…
jpalm
  • 2,297
  • 1
  • 21
  • 27
40
votes
5 answers

Google Cloud Messaging - messages sometimes not received until network state changed

While working on a little project that integrates with GCM, I've stumbled across a bit of a strange issue. Some times when I start watching the log to see if messages are received, messages do not appear to be coming through until I have changed the…
Seidr
  • 4,946
  • 3
  • 27
  • 39
38
votes
2 answers

Intent action for network events in android sdk

I need to receive broadcasts for network actions like network connected, disconnected etc. I am using a broadcast receiver for this purpose. Can anyone please tell me which intent action I need to capture for network events, right now as per my…
mudit
  • 25,306
  • 32
  • 90
  • 132
1
2 3
61 62