Android targeting templates

Source: Internet
Author: User

Private voidgetlocationcity () {String serviceName=Context.location_service; Locationmanager=(Locationmanager) Getsystemservice (serviceName);//String Provider = Locationmanager.gps_provider;String Provider =Locationmanager.network_provider; Criteria Criteria=NewCriteria ();        Criteria.setaccuracy (Criteria.accuracy_fine); Criteria.setaltituderequired (false); Criteria.setbearingrequired (false); Criteria.setcostallowed (true); Criteria.setpowerrequirement (criteria.power_low);//String Provider = Locationmanager.getbestprovider (criteria, true);
Locationmanager.requestlocationupdates (provider,                N, locationlistener);
 Location Location=locationmanager.getlastknownlocation (provider);   GetAddress (location);     }    Private FinalLocationlistener Locationlistener =NewLocationlistener () { Public voidonlocationchanged (location) {getaddress); }         Public voidonproviderdisabled (String provider) {getaddress (NULL); }         Public voidonproviderenabled (String provider) {} Public voidOnstatuschanged (String provider,intstatus, Bundle extras)    { }    }; Private voidgetaddress (location location) {if(Location! =NULL) {            Newmyasynccity (). Execute (location); } Else{log.d (TAG,"Updatewithnewlocation:"); }    }    Private classMyasynccityextendsAsynctask<location, Void, string>{@OverrideprotectedString doinbackground (location ... params) {List<Address> addlist =NULL; Geocoder GE=NewGeocoder (welcomeactivity. This); Try{addlist= Ge.getfromlocation (Params[0].getlatitude (), Params[0].getlongitude (), 1); } Catch(IOException e) {e.printstacktrace (); }            returnAddlist.get (0). Getlocality (); } @Overrideprotected voidOnPostExecute (String city) {Super. OnPostExecute (city);        Sputil.setlocationcity (city); }    }

Android targeting templates

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.