android-internet

Detect if Android device has Internet connection

夙愿已清 提交于 2019-11-26 03:15:01
问题 I need to tell if my device has Internet connection or not. I found many answers like: private boolean isNetworkAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null; } (Taken from Detect whether there is an Internet connection available on Android.) But this is not right, for example if I\'m connected to a

Http Get using Android HttpURLConnection

谁说胖子不能爱 提交于 2019-11-26 02:19:40
问题 I\'m new to Java and Android development and try to create a simple app which should contact a web server and add some data to a database using a http get. When I do the call using the web browser in my computer it works just fine. However, when I do the call running the app in the Android emulator no data is added. I have added Internet permission to the app\'s manifest. Logcat does not report any problems. Can anyone help me to figure out what\'s wrong? Here is the source code: package com

Detect whether there is an Internet connection available on Android [duplicate]

六眼飞鱼酱① 提交于 2019-11-25 21:41:05
问题 I need to detect whether the Android device is connected to the Internet. The NetworkInfo class provides a non-static method isAvailable() that sounds perfect. Problem is that: NetworkInfo ni = new NetworkInfo(); if (!ni.isAvailable()) { // do something } throws this error: The constructor NetworkInfo is not visible. Safe bet is there is another class that returns a NetworkInfo object. But I don\'t know which. How to get the above snippet of code to work? How could I have found myself the