java - Android Studio: Unable to resolve Symbol 'requestLocationUpdates' -
working basic gps code , running issue new android studio - mean preview software far has been reliable enough used full time. here code giving me issue:
import android.app.activity; import android.app.alertdialog; import android.content.context; import android.content.dialoginterface; import android.content.intent; import android.location.location; import android.location.locationlistener; import android.location.locationmanager; import android.os.bundle; import android.widget.textview; public class whereami extends activity implements locationlistener{ textview lat, lon, alt, status; context mycontext = this; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.whereami); lat = (textview)findviewbyid(r.id.lattxt); lon = (textview)findviewbyid(r.id.lontxt); alt = (textview)findviewbyid(r.id.alttxt); status = (textview)findviewbyid(r.id.gpsstatus); } /* use locationmanager class obtain gps locations */ locationmanager lm = (locationmanager) getsystemservice(location_service); //gather gps data @ time interval. lm.requestlocationupdates(locationmanager.gps_provider, 1, 1f, mycontext); //check see if gps on boolean isgps = lm .isproviderenabled(locationmanager.gps_provider); //if off, request turn on. if (isgps == false) { //enable gps pop-up notification. alertdialog.builder adb = new alertdialog.builder(mycontext); // set title adb.settitle("enable gps?"); // set dialog message adb.setmessage("enable gps full function app."); adb.setcancelable(false); //yes button adb.setpositivebutton("yes", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { startactivityforresult( new intent( android.provider.settings.action_location_source_settings), 0); } }); //no button adb.setnegativebutton("no", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { dialog.cancel(); } }); // create gps alert [pop-up] alertdialog alertdialog = adb.create(); // show alertdialog.show(); } else { //added when app gets refreshed show true gps info status. status.settext("gps status: enabled"); } @override public void onlocationchanged(location location) { lat.settext("latitude: " + location.getlatitude()); lon.settext("longitude: " + location.getlongitude()); alt.settext("altitude: " + location.getaltitude()); } @override public void onstatuschanged(string s, int i, bundle bundle) { } @override public void onproviderenabled(string s) { status.settext("gps status: enabled"); } @override public void onproviderdisabled(string s) { } }
for reason keeps coming cant resolve symbol requestlocationupdates.
anyone else run or know solution?
there no requestlocationupdates()
function takes context
input. following allowed parameters requestlocationupdates() function:
requestlocationupdates(long mintime, float mindistance, criteria criteria, pendingintent intent) requestlocationupdates(long mintime, float mindistance, criteria criteria, locationlistener listener, looper looper) requestlocationupdates(string provider, long mintime, float mindistance, locationlistener listener) requestlocationupdates(string provider, long mintime, float mindistance, locationlistener listener, looper looper) requestlocationupdates(string provider, long mintime, float mindistance, pendingintent intent)
see locationmanager page well. hope helps.
update
shift following code inside oncreate()
:
/* use locationmanager class obtain gps locations */ locationmanager lm = (locationmanager) getsystemservice(location_service); //gather gps data @ time interval. lm.requestlocationupdates(locationmanager.gps_provider, 1, 1f, mycontext); //check see if gps on boolean isgps = lm .isproviderenabled(locationmanager.gps_provider); //if off, request turn on. if (isgps == false) { //enable gps pop-up notification. alertdialog.builder adb = new alertdialog.builder(mycontext); // set title adb.settitle("enable gps?"); // set dialog message adb.setmessage("enable gps full function app."); adb.setcancelable(false); //yes button adb.setpositivebutton("yes", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { startactivityforresult( new intent( android.provider.settings.action_location_source_settings), 0); } }); //no button adb.setnegativebutton("no", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { dialog.cancel(); } }); // create gps alert [pop-up] alertdialog alertdialog = adb.create(); // show alertdialog.show(); } else { //added when app gets refreshed show true gps info status. status.settext("gps status: enabled"); }
Comments
Post a Comment