Use location popup in some new android apps -


hi have seen these popups in new android apps,clicking on yes automatically turn on location services , wifi. want know how done or new feature play services?i implement thing next update of app. popup image can been seen in followwing url http://i.stack.imgur.com/ep4qd.png

do way,

public interface icommand {     void execute(); } 

the 2 concrete commands used enable gps , cancel buttons of alert dialog:

public class cancelcommand implements icommand {     protected activity m_activity;      public cancelcommand(activity activity)     {         m_activity = activity;     }      public void execute()     {         dialog.dismiss();         //start asyncronous operation here     } }   public class enablegpscommand extends cancelcommand {     public enablegpscommand( activity activity) {         super(activity);     }      public void execute()     {         // take user phone gps settings , start asyncronous logic.         m_activity.startactivity(new intent(settings.action_location_source_settings));         super.execute();     } } 

and now, activity:

/returns true if gpsproviderisdisabled //false otherwise private boolean enablegpsifpossible() {        final locationmanager manager = (locationmanager) getsystemservice( context.location_service );     if ( !manager.isproviderenabled( locationmanager.gps_provider ) ) {         buildalertmessagenogps();         return true;     }     return false; }   private  void buildalertmessagenogps() {     final alertdialog.builder builder = new alertdialog.builder(this);     builder.setmessage("yout gps seems disabled, want enable it?")         .setcancelable(false)         .setpositivebutton("yes", new commandwrapper(new enablegpscommand(this)))         .setnegativebutton("no", new commandwrapper(new cancelcommand(this)));       final alertdialog alert = builder.create();     alert.show(); } 

now activity oncreate methodi call:

@override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.newfriendlist);      initializecomponents();      if (!enablegpsifpossible())     {         //then gps enabled , need startfriendretrievalasync here.         //otherwise code being executed enablegpsifpossible() logic.           //asyncronous logic here.     } } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -