Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Robin Potter
Robin Potter
7,267 Points

How To Detect Network Connectivity On Android?

NetworkInfo and getActiveNetworkInfo() are deprecated.

I have no idea how to check for network connection, I have also seen the Android Docs and I didn't understand what I should do.

I have also searched on the internet and nothing really helped me. I have seen solution that doesn't work other different APIs.

What am I supposed to do to check for network connectivity?

Thank you.

2 Answers

See this stackoverflow article... https://stackoverflow.com/questions/57277759/getactivenetworkinfo-is-deprecated-in-api-29

I haven't tested this. Hope it helps

Robin Potter
Robin Potter
7,267 Points

Hello Robert, thanks for your replay.

The first solution is written in Kotlin, and the second solution doesn't check if the network connection is available on API 29.

Is it possible to check if the network connection is available on all Google APIs? If that is not possible, what should we as developers do in order to achieve as much google APIs as possible?

Robin Potter
Robin Potter
7,267 Points

I am still waiting for an answer.

I can't answer the other question at the moment. It has been quite a while since I got into some android development so once I get back into it I will see if I can do some testing. I've been hard at on Python, SQL, and PHP. If you find a solution before then please post here!