Note that there are some explanatory texts on larger screens.

plurals
  1. POLocationManager never triggers, Latitude and Logitude
    primarykey
    data
    text
    <p>I need to get the current location, saved these to a <code>Bundle</code> and forward them to a <code>BroadCastReceiver</code>, which will trigger every 5th second. This is how I structured my code</p> <pre><code>public class GPSServiceActivity extends Activity { public Bundle locationBundle; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); locationBundle = new Bundle(); Calendar cal = Calendar.getInstance(); getCurrentLocation(); Intent intent = new Intent(GPSServiceActivity.this, GPSHandler.class); intent.putExtra("Latitude", locationBundle.getDouble("Latitude")); intent.putExtra("Longitude", locationBundle.getDouble("Longitude")); // In reality, you would want to have a static variable for the request // code instead of 192837 PendingIntent sender = PendingIntent.getBroadcast(this, 192837, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Get the AlarmManager service AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 5000, sender); } public void getCurrentLocation() { LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener mlocListener = new MyLocationListener(); mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, mlocListener); } /* Class My Location Listener */ public class MyLocationListener implements LocationListener { public void onLocationChanged(Location loc) { double Latitude = loc.getLatitude(); double Longitude = loc.getLongitude(); locationBundle.putDouble("Longitude", Longitude); locationBundle.putDouble("Latitude", Latitude); } public void onProviderDisabled(String arg0) { } public void onProviderEnabled(String arg0) { } public void onStatusChanged(String arg0, int arg1, Bundle arg2) { } } </code></pre> <p>}</p> <p>My <code>Manifest.xml</code></p> <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt; &lt;uses-permission android:name="android.permission.INTERNET"/&gt; </code></pre> <p>After some time debugging the code, I found out that the <code>MyLocationListener</code> never triggers, the <code>Bundle locationBundle</code> just contains two double with the value 0.0 and 0.0. Can somebody give me a hint on how to get this up and running? </p> <p><strong>EDIT</strong></p> <p>Just for test purposes I wrote this code</p> <pre><code>List&lt;String&gt; providers = mlocManager.getAllProviders(); if(providers.size() &gt; 0) { for(int i = 0; i &lt; providers.size(); i++) { Log.i("Providers: ", providers.get(i).toString()); } } else Log.i("Providers: ", "No providers"); </code></pre> <p>And this outputs</p> <pre><code>network gps passive </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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