1
The snippet below has the mission to give a warning to the user if he entered an area of terrain 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);
will not work by itself naturally because it is incomplete. Lack instantiation LocationManager
and also register the BroadcastReceiver
which, from what I understand, works almost like a Listener.
The IntentFilter
associated with some action. And this is my problem.
How to register the Broadcastreceiver for the required action, which is triggered by the method addProximityAlert
?
I did not find something similar to, for example,
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CAMERA_BUTTON);
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
registerReceiver(intentReceiver, intentFilter);
who would watch the click of a camera button.
(This object intentReceiver
above - in the record of receiver - is the instantiation at another point of the code of a particular class that extended BroadcastReceiver
, whose unique method onReceive
would filter if there would be such a click on the camera button)
Ali, no IntentFilter
parallel to my problem, the watched action is the click on the camera.
How to make a similar one in order to record the effective response of the method addProximityAlert
?
Dear @ramaral, I would like to call it off, but I think my 'reputation' still doesn’t allow it. Better, nor would know how to do it by the mechanisms of the forum. Thank you very much.
– user4701
You only need to click on the "V" that is on the left side of the answer, next to the number zero. See here
– ramaral
I forgot to mention it. And that line that defines the action to be 'watched', which says intentFilter.addAction, for use in Broadcastreceiver onReceive is not required?
– user4701
In this case no. In the constructor you are already indicating the
Action
. This is only necessary if you want theIntent
respond to more than one action. Android documentation explains in detail how this works: link1, Link2– ramaral