BroadcastReceiver - how to register for the addProximityAlert method

1
The snippet below has the mission of giving a warning to the user if he has entered an area of land that is a circle around the given geographical coordinates:

double mLatitude=35.41;
double mLongitude=139.46;

float mRadius=500f;

long expiration=-1;

Intent mIntent = new Intent ("Você entrou na área demarcada");

PendingIntent mFireIntent = PendingIntent.getBroadCast(this,-1,mIntent,0);

mLocationManager.addProximityAlert(mLatitude, mLongitude, mRadius, expiration, mFireIntent);

It will not work naturally because it is incomplete. It is not necessary to instantiate LocationManager and also to register BroadcastReceiver which, as I understand it, works almost like a listener .

The IntentFilter associated with some action is still missing. And that's my problem.

How to register BroadcastReceiver for the required action, which is triggered by the addProximityAlert method?

I did not find anything similar to, for example,

IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CAMERA_BUTTON);
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
registerReceiver(intentReceiver, intentFilter);

I would watch the click of a camera button.

is the instantiation at another point in the code of a particular class that has extended% with%, whose unique% method of% would filter if there would be such a click on the camera button)

There, parallel to my problem, the monitored action is the click of the camera.

How to make a similar one, so as to record the effective response of the intentReceiver method?

    
asked by anonymous 07.02.2014 / 12:04

1 answer

1

When you create the IntentFilter you define the action that you want. It is no more than a String.

You just have to make sure that this String is unique. Usually the package name is used plus something that identifies the action.

For example: namePackage.ProximityAlert

The IntentFilter would then be instantiated like this:

IntentFilter intentFilter = new IntentFilter("nomePackage.ProximityAlert");  

Do not forget that Intent should also be created with this IntentFilter :

Intent mIntent = new Intent ("nomePackage.ProximityAlert");

PendingIntent mFireIntent = PendingIntent.getBroadCast(this,-1,mIntent,0);

mLocationManager.addProximityAlert(mLatitude, mLongitude, mRadius, expiration, mFireIntent);  

To facilitate it is usual to declare a static value to save the Filter String:

public static final String PROX_ALERT_INTENT = "nomePackage.ProximityAlert";
    
07.02.2014 / 12:37