View Single Post
  #1 (permalink)  
Old July 14th, 2013, 06:21 AM
ysayeda ysayeda is offline
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default WhereAmI project

Hi ,
I'm trying to create GPS alert notification when we the mobile arrive to specific point in 100m radius.
this is my code that deal with, please let me know what i'm doing wrong:

the setProximityAlert methud :

private void setProximityAlert(){

String locService = Context.LOCATION_SERVICE;
LocationManager locationManager;
locationManager = (LocationManager) getSystemService(locService);

double lat = 31.59819563;
double lng = 34.78952749;
float radius = 100f; //meters
long expiration = -1; // never stop

Intent intent = new Intent(TREASURE_PROXIMITY_ALERT);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, -1, intent, 0);

locationManager.addProximityAlert(lat, lng, radius, expiration, proximityIntent);


}

the ProximityIntentReceiver class :

package com.example.whereami;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;

public class ProximityIntentReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
String key = LocationManager.KEY_PROXIMITY_ENTERING;

boolean entering = intent.getBooleanExtra(key, false);
if (entering) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Pay attention!");
alertDialog.setMessage("You are going to ......");
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.setButton(DialogInterface.BUTTON_POSIT IVE, "YES", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface arg0, int arg1) {

}
});
alertDialog.setButton(DialogInterface.BUTTON_NEGAT IVE, "NO", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub

}
});
} else {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Pay attention!");
alertDialog.setMessage("There is no signal");
alertDialog.setCanceledOnTouchOutside(false);
}

}

}
Reply With Quote