I want to make an app. to which automatically starts as soon as I connect my internet connection and calculates the time for which I was online. After disconnecting the software should automatically write the used hours in a file.
I want to know how to detect that my internet connection is on?

Please help me to get started.

Thanks in advance.

Kinjal