开发者

Sending data to a server when the device is connected to Internet

开发者 https://www.devze.com 2022-12-20 23:42 出处:网络
My app needs to send some data to a server when the devic开发者_如何学Ce is connected. I have been reading about native Android Broadcast actions. I was willing to find a way to use one as gmail does

My app needs to send some data to a server when the devic开发者_如何学Ce is connected.

I have been reading about native Android Broadcast actions. I was willing to find a way to use one as gmail does when the device connects to the Internet. (The "loading" icon on the top while it syncs mails)

Is it ACTION_SYNC what I am looking for?

If not, how does gmail knows when the device connects to internet?


You need to register a receiver like this:

    <receiver android:name=".receiver.ConnectivityReceiver" android:enabled="true">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        </intent-filter>
    </receiver>

More details here: http://code.google.com/events/io/2009/sessions/CodingLifeBatteryLife.html (PDF should be enough).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号