p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Android 4 Application Development (http://p2p.wrox.com/forumdisplay.php?f=685)
-   -   WhereAmI project (http://p2p.wrox.com/showthread.php?t=90510)

ysayeda July 14th, 2013 06:21 AM

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);
}

}

}


All times are GMT -4. The time now is 05:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.