1
A
回答
4
嘿,夥計.. 。申請此代碼..這可能有助於提前u.thanks ....
布爾連接;
private boolean checkInternetConnection()
{
ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
// ARE WE CONNECTED TO THE NET
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected())
{
return true;
}
else
{
return false;
}
}
2
ConnectivityManager connectionService =
(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
if (connectionService.getActiveNetworkInfo().isConnectedOrConnecting()) {
// Device is online
}
1
使用下列函數序上網查connction:
public boolean isOnline()
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
boolean result = false;
if(ni != null)
{
if( ni.getState() == NetworkInfo.State.CONNECTED)
{
result = true;
}
}
return result;
}
檢查什麼isOnline()回報。如果真的,那麼互聯網連接其他Inernet沒有連接。 希望這會幫助你.. :)
0
使用這個答案它的幫助。
public boolean isOnline() {
ConnectivityManager cm =(ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
if(temp==true){
genHelper.showToast("Net Connection");
}else{
genHelper.showToast(" Not Connected");
}
1
// Network is connected or not
public boolean isConnected()
{
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if(connectivity != null)
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
Log.d("LOG","Network is Available");
return true;
}
}
return false;
}
相關問題
- 1. 如何知道socket.Io是否連接android
- 2. 如何知道網絡是否連接?
- 3. 如何知道本地區域連接是否可用
- 4. 如何知道在使用Parse.com時是否有Internet Android
- 5. 在Android中檢查Internet連接是否經常可用?
- 6. 代理(如squid)如何知道連接是否使用http?
- 7. 如何知道url是否可用?
- 8. 如何知道fastcgi_finish_request()是否可用?
- 9. 如何知道用戶是否連接到互聯網?
- 10. 你如何知道CA是否可信?
- 11. 如何知道您是否連接到Wifi Hotspot/Wifi/Wifi Direct
- 12. 如何知道IEEE 1394(FireWire)是否連接到我的Windows 7?
- 13. 如何知道Josso 1是否已成功連接到LDAP?
- 14. 如何立即知道與Socket.IO連接是否丟失?
- 15. 如何知道互聯網連接是否存在?
- 16. 我如何知道服務器的連接是否正確?
- 17. 我如何知道連接是否與websockets一起存在?
- 18. 如何快速知道服務器是否連接?
- 19. 如何知道所連接的windowstation是否互動?
- 20. 如何知道wifi是否與新的Android連接Lollipop wifi管理
- 21. UPS WorldShip如何知道Internet Explorer是否啓動?
- 22. 如何知道是否
- 23. Axapta 2009確定Internet連接是否可用?
- 24. Android如何檢查Internet連接?
- 25. 我如何知道Android應用程序重新連接到Socket.io?
- 26. 如何使用Visual C++ Win32 API知道Internet連接詳細信息
- 27. Laravel知道連接是否已經應用
- 28. 如何知道7zip是否使用AES256?
- 29. 如何知道MediaScanner是否已啓用?
- 30. 如何知道Android應用程序是否被禁用ICS