android - Check Internet during SplashScreen -
well, after splashscreen
screen. app check internet connection. if there internet available, call webview
. otherwise, call 1 activity of error.
but how pair check internet during splashscreen?
activity splash screen:
public class splash extends activity{ private static int tempo_splash = 1000; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.splash); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); // para o layout preencher toda tela cel (remover barra de tit.) new timer().schedule(new timertask() { public void run() { finish(); intent intent = new intent(); intent.setclass(splash.this, mainactivity.class); //chamando classe splash e principal (main) startactivity(intent); } }, 2000); } }
my class checkinternet:
public class checkinternet extends activity{ boolean status = false; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.internet); button btnstatus = (button) findviewbyid(r.id.check_btn); btnstatus.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { status = checkinternetconnection(); if (status) { new handler().postdelayed(new runnable() { @override public void run() { final intent mainintent = new intent(checkinternet.this, mainactivity.class); checkinternet.this.startactivity(mainintent); checkinternet.this.finish(); } }, 5000); } else { toast.maketext(getapplicationcontext(), "you don't have internet connection. try again", toast.length_long).show(); } } }); } public boolean checkinternetconnection() { connectivitymanager connectivity = (connectivitymanager)getapplicationcontext().getsystemservice(context.connectivity_service); if (connectivity != null) { networkinfo[] inf = connectivity.getallnetworkinfo(); if (inf != null) { (int = 0; < inf.length; i++) { return true; } } } return false; } }
try code... maybe you
public class splashscreen extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setrequestedorientation(activityinfo.screen_orientation_portrait); setcontentview(r.layout.splash_screen); if(isworkinginternetpersent()){ splash(); } else{ showalertdialog(splashscreen.this, "internet connection", "you don't have internet connection", false); } } public void splash() { thread timertread = new thread() { public void run() { try { sleep(4000); } catch (interruptedexception e) { e.printstacktrace(); } { intent intent = new intent(getapplicationcontext(), new_main_activity.class); intent.setflags(intent.flag_activity_clear_top | intent.flag_activity_new_task); startactivity(intent); finish(); } } }; timertread.start(); } public boolean isworkinginternetpersent() { connectivitymanager connectivitymanager = (connectivitymanager) getbasecontext() .getsystemservice(context.connectivity_service); if (connectivitymanager != null) { networkinfo[] info = connectivitymanager.getallnetworkinfo(); if (info != null) (int = 0; < info.length; i++) if (info[i].getstate() == networkinfo.state.connected) { return true; } } return false; } public void showalertdialog(context context, string title, string message, boolean status) { alertdialog alertdialog = new alertdialog.builder(context).create(); // setting dialog title alertdialog.settitle(title); // setting dialog message alertdialog.setmessage(message); // setting alert dialog icon // alertdialog.seticon((status) ? r.mipmap.ic_launcher : r.mipmap.ic_launcher); // setting ok button alertdialog.setbutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { finish(); system.exit(0); } }); // showing alert message alertdialog.show(); }