Check if we are connected (WIFI/3-4G) - Android Java -


i have splashscreen (for try internet), if can't connect, don't launch app.

so, have try found 1 java class on internet , have found :https://stackoverflow.com/a/6987498/5070495

i have adapt code, have error in

if (splashscreen.getinstance(this).isonline()) { 

error :

getinstance(android.content.context')in 'com.srazzz.package.splashscreen' cannot applied '(anonymous java.lang.thread') 

all class

public class splashscreen extends activity {     static context context;     connectivitymanager connectivitymanager;     networkinfo wifiinfo, mobileinfo;     boolean connected = false;     private static splashscreen instance = new splashscreen();      public static splashscreen getinstance(context ctx) {         context = ctx.getapplicationcontext();         return instance;     }      public boolean isonline() {         try {             connectivitymanager = (connectivitymanager) context                     .getsystemservice(context.connectivity_service);              networkinfo networkinfo = connectivitymanager.getactivenetworkinfo();             connected = networkinfo != null && networkinfo.isavailable() &&                     networkinfo.isconnected();             return connected;           } catch (exception e) {             system.out.println("checkconnectivity exception: " + e.getmessage());             log.v("connectivity", e.tostring());         }         return connected;     }      @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.splash);          thread timerthread = new thread(){             public void run(){                 try{                     sleep(3000);                  }catch(interruptedexception e){                     e.printstacktrace();                 }finally{                      if (splashscreen.getinstance(this).isonline()) {                          intent = new intent(splashscreen.this, mainactivity.class);                         startactivity(i);                      } else {                          //toast t = toast.maketext("test").show();                         //log.v("home", "############################you not online!!!!");                         intent = new intent(splashscreen.this, chatonly.class);                         startactivity(i);                     }                  }             }         };         timerthread.start();     }      @override     protected void onpause() {         // todo auto-generated method stub         super.onpause();         finish();     }    } 

use this,

new handler().postdelayed(new runnable() {              @override             public void run() {                 if (isonline()) {                             intent = new intent(splashscreen.this, mainactivity.class);                         startactivity(i);                      } else {                          //toast t = toast.maketext("test").show();                         //log.v("home", "############################you not online!!!!");                         intent = new intent(splashscreen.this, chatonly.class);                         startactivity(i);                     }             }         }, 3000); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -