Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem while implement location listener in android appwidget
    primarykey
    data
    text
    <p>I am working on a Widget which will get the Current GPS location and pass this value to remote PHP page to get the Information and display it in the Widget. This is what I am trying to do.</p> <p>I am facing problem while implementing Location Listener for appWidget. It is not updating with the Current Location and It is showing the initial widget i.e "Loading Widget"(Here I put this text)</p> <p><strong>Can we implement Location Listener for AppWidgetProvider?</strong><br> Or<br> <strong>Can you suggest me the possible solution for getting GPS location in App Widget?</strong></p> <p>I placed all necessary permissions in Manifest file.<br> Here is my code snippet: <br> <code></p> <pre><code>public class test extends AppWidgetProvider { static LocationManager locMan; static Location curLocation; static Boolean locationChanged; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) { // To prevent any ANR timeouts, we perform the update in a service context.startService(new Intent(context, UpdateService.class)); } public static class UpdateService extends Service { // GPS Listener Class LocationListener gpsListener = new LocationListener() { public void onLocationChanged(Location location) { // Log.w("GPS", "Started"); if (curLocation == null) { curLocation = location; locationChanged = true; } if (curLocation.getLatitude() == location.getLatitude() &amp;&amp; curLocation.getLongitude() == location.getLongitude()) locationChanged = false; else locationChanged = true; curLocation = location; if (locationChanged) locMan.removeUpdates(gpsListener); } public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { // Log.w("GPS", "Location changed", null); } public void onStatusChanged(String provider, int status, Bundle extras) { if (status == 0)// UnAvailable { } else if (status == 1)// Trying to Connect { } else if (status == 2) {// Available } } }; // In service start method, I am registering for GPS Updates @Override public void onStart(Intent intent, int startId) { locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (locMan.isProviderEnabled(LocationManager.GPS_PROVIDER)) { locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,20000, 1, gpsListener); } else { this.startActivity(new Intent("android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS")); } if (curLocation != null) { double lat = curLocation.getLatitude(); double lng = curLocation.getLongitude(); Toast.makeText(getBaseContext(),"Lat : " + String.valueOf(lat) + "\n Long : "+ String.valueOf(lng), Toast.LENGTH_LONG).show(); } // Build the widget update for today RemoteViews updateViews = buildUpdate(this); // Push update for this widget to the home screen ComponentName thisWidget = new ComponentName(this,InKakinadaWidget.class); AppWidgetManager manager = AppWidgetManager.getInstance(this); manager.updateAppWidget(thisWidget, updateViews); } public RemoteViews buildUpdate(Context context) { // Here I am updating the remoteview return updateViews; } @Override public IBinder onBind(Intent intent) { // We don't need to bind to this service return null; } } } </code></pre> <p></code></p> <p>Thanks in Advance...</p> <p>With Regards, Raghavendra K.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload