android-internet

how to read and use the content of a website in android app

你说的曾经没有我的故事 提交于 2019-12-11 03:53:13
问题 I actually have to read and use the content of some website in an Android app. I majorly e used two different codes till now to get the content of a website but they did not work for me public static String connect(String url) { String result = "bubububu" ; HttpClient httpclient = new DefaultHttpClient(); // Prepare a request object HttpGet httpget = new HttpGet(url); // Execute the request HttpResponse response; try { response = httpclient.execute(httpget); // Examine the response status Log

How to send file / message between two android device with out any intermediate server

青春壹個敷衍的年華 提交于 2019-12-10 21:48:23
问题 I want to send files between two devices using internet connection with out use any intermediate /server. For example there are two device A and B both have internet connection and both device have installed my application, now need to send a file from Device A to Device B. Device A can know all the detail about the Device B. Is this possible means guide me in the correct way. Thanks in advance. 回答1: You can use a Peer to Peer architecture to achieve this. Basically every phone is a client

How I can check android device is connected to the Internet? [duplicate]

笑着哭i 提交于 2019-12-08 10:10:41
问题 This question already has answers here : How to handle “no internet connection” scenario when sending requests? (2 answers) Closed 2 years ago . Is there any way to find out that android device is connected to the Internet or not. I use this function: public boolean isDeviceOnline() { ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnectedOrConnecting(); } but

How to wait for an IntentService to finish its task

孤街浪徒 提交于 2019-12-08 02:58:24
问题 I'm using an intent service to communicate with a server to get data for an app. I'd like the app to wait until the data it requests has been sent back (hopefully meaning that the IntentService the data has been requested from has finished running) before the app attempts to access or use the variables the data is to be stored in. How would I go about doing this? thanks! 回答1: Easiest way is to have your IntentService send a Broadcast once it is done gathering data from the server, which you

Effective way to check for slow internet connection and differentiate between network connection and actual internet connection in android

自闭症网瘾萝莉.ら 提交于 2019-12-07 12:34:25
How to check if the device is connected to internet or it is just connected to external wifi network? Because NetworkInfo returns true if a device is connected to an external wifi network even there is no network connection. When device is connected to wifi but there is no internet access,my app's network connectivity-check class returns true but application crashes with the exception that it cannot access the corresponding http url. If you want to know when you have an active internet connection, do something like this: Some static variables: /** * Set the number of retries when

Detect if android device is connected to the internet

落爺英雄遲暮 提交于 2019-12-07 10:00:39
问题 this is my class that checks if the device is connected to the internet. import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class ConnectionDetector { private Context _context; public ConnectionDetector(Context context) { this._context = context; } public boolean isConnectingToInternet() { if

How to wait for an IntentService to finish its task

喜夏-厌秋 提交于 2019-12-06 08:49:59
I'm using an intent service to communicate with a server to get data for an app. I'd like the app to wait until the data it requests has been sent back (hopefully meaning that the IntentService the data has been requested from has finished running) before the app attempts to access or use the variables the data is to be stored in. How would I go about doing this? thanks! Easiest way is to have your IntentService send a Broadcast once it is done gathering data from the server, which you can listen to in your UI thread (e.g. Activity ). public final class Constants { ... // Defines a custom

Detect if android device is connected to the internet

此生再无相见时 提交于 2019-12-05 16:13:07
this is my class that checks if the device is connected to the internet. import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class ConnectionDetector { private Context _context; public ConnectionDetector(Context context) { this._context = context; } public boolean isConnectingToInternet() { if (networkConnectivity()) { try { HttpURLConnection urlc = (HttpURLConnection) (new URL( "http://www.google

ConnectivityManager.EXTRA_NO_CONNECTIVITY is always false on Android Lollipop

自古美人都是妖i 提交于 2019-12-03 17:47:43
问题 I am using this piece of code to detect Internet connection state changes. It works fine on Android<5.0, but on API 21 this: intent.getExtras().getBoolean(ConnectivityManager.EXTRA_NO_CONNECTIVITY) is always false. How to make this code to work on Android 5.0? My BroadcastReceiver: public class NetworkStateReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, final Intent intent) { if(intent.getExtras()!=null) { final ConnectivityManager

Cannot make a static reference to the non-static method getSystemService(String) from the type

夙愿已清 提交于 2019-12-03 13:06:02
问题 I have this function which network connection public boolean isNetworkConnected() { ConnectivityManager conManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = conManager.getActiveNetworkInfo(); if (netInfo == null) { // There are no active networks. return false; } else { return true; } } But when i a trying to make it static so that i can use it in every activity it is throwing: Cannot make a static reference to the non-static method