0

I want to know if there any listener, like onClickListener , but for connection to the Internet. I want to start some function, only when there is a new connection to Internet. Exactly like a Button, that till it is not pressed, it's not start the onClick.

Does someone know something like that?

Thanks in advance!

Itay
  • 219
  • 5
  • 14
  • @Devrath how BROADCAST RECEIVER could help me? – Itay Jul 29 '14 at 16:26
  • See this solution http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-timeouts – QArea Aug 05 '14 at 17:41

1 Answers1

2

Check out BROADCAST RECIEVER

  • What happens is as soon if a change in network ex:Internet, android fires an intent
  • You can use this Intent as per your wish to achieve your objective, like performing some tasks
  • You can place the Broadcast reciever in your main activity
  • Don't forget to declare it in manifest

CHECK THIS STACKOVERFLOW POST- IT WILL GIVE YOU THE IDEA ON HOW TO USE

Hope this helps !, comment back if you need any more information

Community
  • 1
  • 1
Devrath
  • 42,072
  • 54
  • 195
  • 297
  • Thanks for reply! How can I get that intent? Do yo have any examlpe code for that? – Itay Jul 29 '14 at 16:29
  • Check the edit ...... it shows on how to do it for wifi .... its similar to internet too .... google for some tutorials ..... its very simpe .... let me know my answer helps to clear your query ! – Devrath Jul 29 '14 at 16:30
  • @Itay .... Were you able to get answer to your question ? .... Check the answer correct if it helps so that it will be helpful to others who come across similar problem ! – Devrath Jul 29 '14 at 16:41
  • I'll check that tomorow :) I just discovered some other problems in my app ^^ – Itay Jul 29 '14 at 22:04
  • Is there any way do it it on service? – Itay Jul 30 '14 at 11:42