开发者

Listen to internet availability in service in android

I already create receiver to test network availability so I can receive when the android has or no network, but how can we listen to internet availability?

The goal. When log in fails (means no internet connection) we have to resend our log in data in Thread in service backgro开发者_StackOverflow中文版und task )


This should do the trick :

 ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
 if( conMgr.getActiveNetworkInfo().isConnectedOrConnecting())
 {
       // your stuff
 }

Remeber to put

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜