Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: location; activity and service
    primarykey
    data
    text
    <p>I'm working on some application that should fetch current location and after device is located in some radius should be shown application with some message. I have a few questions. I'm trying to fetch location using </p> <pre><code>locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000*60*5, 50, locationListener); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000*60*5, 50, locationListener); addProximityAlert(LAT,LONG); private void addProximityAlert(double latitude, double longitude) { Intent intent = new Intent(this.getApplicationContext(), SOME_CLASS_HERE); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //Does this needed even if apllication/activity is alive? PendingIntent proximityIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); //and does this needed again? locationManager.addProximityAlert(latitude, longitude, Radius, 0, proximityIntent); } </code></pre> <ol> <li><p>If I use requestLocationUpdates then GPS is always working. And this is a waste of battery. Maybe there is some way, for example, to pause this for a several minutes? I mean use GPS every 5 minutes for example from one location fetching to next. How to realize this?</p></li> <li><p>If SOME_CLASS_HERE - some activity class, then how I could know if exactly this event called it? Because when ProximityAlert is triggered I need to call some activity's function as well. How could I do this?</p></li> </ol> <hr> <p>UPD: Now I'm using only Activity (I haven't Service at all) I'm trying next:</p> <pre><code>Intent intent = new Intent(getString(R.string.intent_message_location_fetched)); PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0, intent, 0); locationManager.addProximityAlert(LAT, LONG, RADIUS, 0, proximityIntent); </code></pre> <p>As I understand intent with action R.string.intent_message_location_fetched should be fired after location will be around LAT LONG.</p> <p>Then I'm trying to create BroadcastReciver class:</p> <pre><code>public class MyBroadcastReciver extends BroadcastReceiver { MyActivity mainActivity; public MyBroadcastReciver(MyActivity activity) { mainActivity = activity; } @Override public void onReceive(Context context, Intent intent) { mainActivity.ShowToast("Recived : " + intent.getAction()); } } </code></pre> <p>And register reciver in MyActivity class:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myReciver = new MyBroadcastReciver(this); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(getString(R.string.intent_message_location_fetched)); registerReceiver(myReciver, intentFilter); ... </code></pre> <p>But nothing happens when I'm in LAT LONG location. What's wrong? Maybe I should register reciver in AndroidManifest.xml? But how exactly?</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