Check if device is online or offline

by Simon » Fri, 22 Apr 2011 03:39:26 GMT

Sponsored Links

I have hunted around, but can't seem to find an answer to this.  I am
working on an app that will be using local storage through the SQLite
DB, but will also be syncing to a remote server.  If the device is
online, I would like to be able to sync to the remote server, and if
it is offline, I would like to store an event that indicates there is
data to send once the device is online again.  But I can't seem to
find in the API how to query for the current online/offline status of
the device.  Is there something like this available?




Re: Check if device is online or offline

by Mark Murphy » Fri, 22 Apr 2011 04:00:51 GMT

 See ConnectivityManager and getActiveNetworkInfo().

Mark Murphy (a Commons Guy)  |  | 

Android 3.0 Programming Books: 


Sponsored Links

Other Threads

1. Java Help, Replace first line of text file!


I am looking for a way to replace the first line of a file. Until now,
I was using BufferedReader to read the contents of the file into and
then going through each line and look for the one I want to replace.
This caused some memory issues as a large file with large data would
slow things down on the phone. So I moved the line to be the first
line of the file and all I want to do is whenever there is a need,
replace the contents of first line with something else without caring
about the rest of the file.

I have been suggested different ways to do this, StringBuilder,
RandomAccessFile but I am looking for a neat example for any of the
above solutions or any other solution.

Please help




2. Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required!


The above error occurs when I do the following.

I have a text file with multiple lines of data. Within my application
I come across the need to replace a line from the file with a new one.
I am using BufferedReader with a fixed size (50k) to read the file
into as below:

FileReader input_redo = new FileReader(redo);
BufferedReader reader = new BufferedReader(input_redo);

  String line = "", oldtext = "";

     while((line = reader.readLine()) != null)
                 oldtext += line + "\r\n";
     String newtext = oldtext.replaceAll("Hello how are you", "Have I
met you before?");

     FileWriter writer = new FileWriter("/sdcard/data/replace.txt");

Could anyone please help me out with this error? I know the device is
running out of memory bcoz of the buffer size or something but don't
know a work around for this. Please help



3. MMS URI Structure

4. tanya mesenggeran yg irit batere di android

5. ProgressDialog - how to remove the numbers

6. Media control style buttons

7. Intents problem