android - Check Uses Network Location and Alert -


i have simple need. want check if user has enabled use network location checkbox. if enabled, want pass user activity called locationpage. if network location not enabled, want display alert.

this sounds simple going absolutely crazy trying figure out. seems work find if remove check , pass user directly locationpage activity. ideas helpful. thank you!

package com.appname.app;  import android.app.activity; import android.app.alertdialog; import android.content.context; import android.content.dialoginterface; import android.content.intent; import android.location.locationmanager; import android.os.bundle;   public class main extends activity {      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.gpsoff);           thread logotimer = new thread(){             public void run() {                 try{                     int logotimer = 0;                     while (logotimer<6000){                         sleep(100);                         logotimer = logotimer+100;                     }                      locationmanager locmanager =  (locationmanager) this.getsystemservice(context.location_service);                     boolean networkenabled = locmanager.isproviderenabled(locationmanager.network_provider);                      if(!networkenabled){                           alertdialog alertdialog = new alertdialog.builder(main.this).create();                         alertdialog.settitle("title");                         alertdialog.setmessage("message");                         alertdialog.setbutton("ok", new dialoginterface.onclicklistener() {                            public void onclick(dialoginterface dialog, int which) {                               // todo add code button here.                            }                         });                         // set icon dialog                         alertdialog.seticon(r.drawable.icon);                         alertdialog.show();                         // see http://www.androidsnippets.com/simple-alert-dialog-popup-with-title-message-icon-and-button                      }                      else {                      startactivity(new intent("com.appname.app.locationpage"));                      }                  } catch (interruptedexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }                  finally{                     finish();                 }             }              private locationmanager getsystemservice(string locationservice) {                 // todo auto-generated method stub                 return null;             }          };         logotimer.start();         }  } 

if i'm getting correctly need.

i here using shared preferences fulfill check box need;

by following code:

 prefs.xml      <checkboxpreference       android:defaultvalue="true"       android:key="alpha"       android:summary="check/uncheck"       android:title="location" /> 

now inflate same prefs.xml in prefsactivity

now in main activity:

      sharedpreferences sp =preferencemanager.getdefaultsharedpreferences(getbasecontext());       boolean result = sp.getboolean("alpha", true);       if (result)        {        if(checknetwrok())         {                 intent = new intent(this, locationpage.class)                 startactivity(i);         {           else          {                 show toast/dialog "network not found !"         }           }   else {            msg: pls enable network checkbox first        }      public boolean checknetwork(){           locationmanager locmanager =  (locationmanager) this.getsystemservice(context.location_service);           boolean networkenabled = locmanager.isproviderenabled(locationmanager.network_provider);         return networkenabled;      } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -