Оповещения о сближении Android не работают

Я пытаюсь создать приложение, которое позволяет вам устанавливать оповещение о близости для маркера, когда вы нажимаете на его информационное окно.

    googleMap.setOnInfoWindowClickListener(
            new OnInfoWindowClickListener(){
     public void onInfoWindowClick(Marker marker) {

         LatLng clickedMarkerLatLng = marker.getPosition();
                double lat =  clickedMarkerLatLng.latitude;
                double long1 =  clickedMarkerLatLng.longitude;

            Log.e("hello", "Output=" + lat + long1);

               LocationManager lm;
         //   double lat=123,long1=34;    //Defining Latitude & Longitude
              float radius=30;                         //Defining Radius

            lm=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
            Intent i= new Intent("com.example.sleepertrain5.ProximityReceiver");           //Custom Action
            PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, i, PendingIntent.FLAG_CANCEL_CURRENT);
            lm.addProximityAlert(lat, long1, radius, -1, pendingIntent);

     }

Это код, который вызывает широковещательный приемник

public class ProximityReceiver extends BroadcastReceiver {

 @Override
 public void onReceive(Context arg0, Intent arg1) {
 // TODO Auto-generated method stub
 // The reciever gets the Context & the Intent that fired the broadcast as arg0 & agr1 

 String k=LocationManager.KEY_PROXIMITY_ENTERING;
// Key for determining whether user is leaving or entering 

 boolean state=arg1.getBooleanExtra(k, false);
 //Gives whether the user is entering or leaving in boolean form

 if(state){
 // Call the Notification Service or anything else that you would like to do here
 Toast.makeText(arg0, "Welcome to my Area", 600).show();
 }else{
 //Other custom Notification 
Toast.makeText(arg0, "Thank you for visiting my Area,come back again !!", 600).show();

 }

}

Выше показан широковещательный приемник. Ничего из этого не работает, и я не могу понять, почему. Любая помощь будет здорово.


person Jordan Moffat    schedule 18.03.2013    source источник


Ответы (1)


Используйте приведенный ниже код для ожидания намерения:

PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),
                nId, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

Где nId будет любым уникальным номером, представляющим конкретное ожидающее намерение.

person Karn Shah    schedule 18.03.2013