ユーザーが特定の場所の近くにいるときにユーザーに通知する方法があるかどうかを知りたい.
ユーザーがその場所に近づくと、電話に通知が届き、自分の場所を思い出させます。
次のコードを試していますが、機能していません。
public class NotifyuserActivity extends Activity {
LocationManager locMan;
double lat;
double lon;
NotificationManager notMan;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locMan=(LocationManager) getSystemService(LOCATION_SERVICE);
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,10, mylistener);
}
LocationListener mylistener= new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
lat = location.getLatitude();
lon = location.getLongitude();
CharSequence from = "AlarmManager - Time's up!";
CharSequence message = "This is your alert";
Location tasklocation=new Location(LocationManager.GPS_PROVIDER);
double dis1 = location.distanceTo(tasklocation);
tasklocation.setLatitude(22.727733);
tasklocation.setLongitude(75.886079);
if(dis1 < 200.00)
{
notMan = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification n = new Notification(R.drawable.ic_launcher, "Click here for details", System.currentTimeMillis());
Intent notificationIntent = new Intent(NotifyuserActivity.this,NotifyuserActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(NotifyuserActivity.this, 0, notificationIntent, 0);
n.setLatestEventInfo(NotifyuserActivity.this, from,message, pendingIntent);
notMan.notify(10001, n);
Toast.makeText(NotifyuserActivity.this,"Distance to location is: " + dis1, Toast.LENGTH_LONG).show();
}
}
};
}