Check if device is online or offline

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


Sponsored Links
 Hi,

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?

Thanks,

Simon

-- 



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)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android 3.0 Programming Books:  http://commonsware.com/books 

-- 


Sponsored Links


Other Threads

1. Error inflating class com.android.launcher2.AllAppsView

I just pulled the 2.1 source recently, and am trying to compile
Launcher2 currently. It compiles fine, but when I push it onto my
phone, it FCs constantly, with the error:

E/AndroidRuntime(13990): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime(13990): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.android.launcher2/
com.android.launcher2.Launcher}: android.view.InflateException: Binary
XML file line #53: Error inflating class android.widget.ImageView
E/AndroidRuntime(13990):        at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2496)
E/AndroidRuntime(13990):        at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2512)
E/AndroidRuntime(13990):        at android.app.ActivityThread.access
$2200(ActivityThread.java:119)
E/AndroidRuntime(13990):        at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime(13990):        at
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(13990):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(13990):        at
android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(13990):        at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(13990):        at
java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(13990):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(13990):        at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(13990):        at dalvik.system.NativeStart.main(Native
Method)
E/AndroidRuntime(13990): Caused by: android.view.InflateException:
Binary XML file line #53: Error inflating class
android.widget.ImageView
E/AndroidRuntime(13990):        at
android.view.LayoutInflater.createView(LayoutInflater.java:513)
E/AndroidRuntime(13990):        at
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:
56)
E/AndroidRuntime(13990):        at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
E/AndroidRuntime(13990):        at
android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
E/AndroidRuntime(13990):        at
android.view.LayoutInflater.inflate(LayoutInflater.java:407)
E/AndroidRuntime(13990):        at
android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime(13990):        at
android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime(13990):        at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:
198)
E/AndroidRuntime(13990):        at
android.app.Activity.setContentView(Activity.java:1622)
E/AndroidRuntime(13990):        at
com.android.launcher2.Launcher.onCreate(Launcher.java:223)
E/AndroidRuntime(13990):        at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
E/AndroidRuntime(13990):        at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2459)
E/AndroidRuntime(13990):        ... 11 more
E/AndroidRuntime(13990): Caused by:
java.lang.reflect.InvocationTargetException
E/AndroidRuntime(13990):        at
android.widget.ImageView.<init>(ImageView.java:105)
E/AndroidRuntime(13990):        at
java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime(13990):        at
java.lang.reflect.Constructor.newInstance(Constructor.java:446)
E/AndroidRuntime(13990):        at
android.view.LayoutInflater.createView(LayoutInflater.java:500)
E/AndroidRuntime(13990):        ... 22 more
E/AndroidRuntime(13990): Caused by: android.content.res.Resources
$NotFoundException: File res/drawable/home_arrows_left.xml from
drawable resource ID #0x7f02000d
E/AndroidRuntime(13990):        at
android.content.res.Resources.loadDrawable(Resources.java:1693)
E/AndroidRuntime(13990):        at
android.content.res.TypedArray.getDrawable(TypedArray.java:548)
E/AndroidRuntime(13990):        at
android.widget.ImageView.<init>(ImageView.java:115)
E/AndroidRuntime(13990):        ... 26 more
E/AndroidRuntime(13990): Caused by: android.content.res.Resources
$NotFoundException: File res/drawable/home_arrows_left_1.xml from
drawable resource ID #0x7f02000e
E/AndroidRuntime(13990):        at
android.content.res.Resources.loadDrawable(Resources.java:1693)
E/AndroidRuntime(13990):        at
android.content.res.Resources.getDrawable(Resources.java:580)
E/AndroidRuntime(13990):        at
android.graphics.drawable.LevelListDrawable.inflate(LevelListDrawable.java:
124)
E/AndroidRuntime(13990):        at
android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:
788)
E/AndroidRuntime(13990):        at
android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
E/AndroidRuntime(13990):        at
android.content.res.Resources.loadDrawable(Resources.java:1690)
E/AndroidRuntime(13990):        ... 28 more
E/AndroidRuntime(13990): Caused by: android.content.res.Resources
$NotFoundException: Resource ID #0x7f02001e
E/AndroidRuntime(13990):        at
android.content.res.Resources.getValue(Resources.java:891)
E/AndroidRuntime(13990):        at
android.content.res.Resources.getDrawable(Resources.java:579)
E/AndroidRuntime(13990):        at
android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:
160)
E/AndroidRuntime(13990):        at
android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:
788)
E/AndroidRuntime(13990):        at
android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
E/AndroidRuntime(13990):        at
android.content.res.Resources.loadDrawable(Resources.java:1690)
E/AndroidRuntime(13990):        ... 33 more

Please help me !!!! thanks very much!!!

-- 

2. launch the keyguard screen

Hi,

I'm trying to launch the keyguard from my activity, is it possible ?

Before, I tried to emulate the ENDCALL key, but i got the permission
error INJECT_EVENT, even if I added it to my manifest. I read that the
plateform doesn't allow it.

So, I tried to disable / reenable the keyguard in order to show it,
but it didn't launch it.

Any idea ?

Thanks

Will

-- 

3. Htc hero Rom Upgrade

4. How to prevent AdView from taking the D-Pad Focus

5. Eh tau ngga....:-)

6. Json Exmpale

7. Best way to expose my Activity to third parties?