addProximityAlert() doesn't fire intent

by Joe77 » Tue, 06 Oct 2009 01:17:56 GMT

Sponsored Links

I am new to Android development and I am trying to write an App that
uses the addProximityAlert() method. I know my intent / intent-filters
work (as I can manually fire the intent) however I cannot seem to get
addProximityAlert to fire an intent. I've searched on various forums
and read the API docs numerous times however have not been able to
determine what is wrong with my code. Any ideas?

package com.example.gpsprox;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class GpsProx extends Activity implements OnClickListener {

private LocationManager lm;
private Proximity prox;
String phoneNo;
String message;
double latitude;
double longitude;
float radius;

private static final String PROXIMITY_ALERT =

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

//---use the LocationManager class to obtain GPS locations---
lm = (LocationManager)

// Use addProximityAlert public method of locationmanager

// Test Latitude / Longitude is at corner of Bute Gardens and
the broadway.

latitude = 51.4935684;
longitude = -0.2223873;
radius = 0;
// Context context;

Intent intent = new Intent(PROXIMITY_ALERT);

PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext
(), 0, intent, 0);

// sendBroadcast(intent);

lm.addProximityAlert(latitude, longitude, radius, -1, pi);

IntentFilter filter = new IntentFilter(PROXIMITY_ALERT);
registerReceiver(new Proximity(), filter);

Button button = (Button)findViewById(;

"Got here!",


// Implement the OnClickListener callback
public void onClick(View v) {

// lm.removeProximityAlert(GpsProx.pi);



public class Proximity extends BroadcastReceiver

public void onReceive(Context context, Intent
intent) {
// TODO Auto-generated method stub

"Got her

Other Threads

1. onCreateContextMenu() not called in Notepad tutorial

Hi all
I am a beginner and I am trying the Notepad tutorial ( exercise 2 to
be precise).

In this onCreateContextMenu() is used to show delete menu. But when I
select a note and press "Menu" , onCreateContextMenu()  is not called;
instead onCreateOptionsMenu() is called.
The tutorial suggests calling registerForContextMenu(getListView());
in onCreate().
 But still it is not called.

I tried getListView().setOnCreateContextMenuListener(this);
still not use.

Has someone seen this issue? Any suggestion what can be wrong ?



2. Skipping the long load time by having the emulator on all the time


I'm developing a game on the Android and the problem I'm running into
is the fact that the actual emulator takes long time to boot. I have
to wait roughly 45s to 75seconds to get into my program. And when
actually doing lot of recompiling I'm wasting too much time for that.

So what can be done to get around this? I'd like to have the emulator
running and just upload the new program into it and run it instantly.
Is there a way to have the emulator up and running and upload the
program into it every time I compile, so I wouldn't have to wait for
the boot up time of the emulator?

All tips and tricks are definitely welcome.
Thank you.

- Mika


3. Mediastore Thumbnails not generated until Gallery app is launched ?

4. How to bring up the keyboard from WebViewClient

5. You must supply a resource ID for a TextView

6. Issue with allocation tracker: I cannot get it to work.

7. undefined behavior with getResultExtras and setResultExtras