특정 좌표를 입력하고 그 좌표의 몇미터 근방에 들어오면 어떤 이벤트를 주려는 작업을 하려고 합니다.
책에는 예제 소스가 다음과 같은것이 있는데요 잘안되네요..
//LocationAlert .java
package exam.location;
import android.app.*;
import android.content.*;
import android.location.*;
import android.os.*;
public class LocationAlert extends Activity {
LocationManager mLocMan;
PendingIntent mPending;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_locationalert);
mLocMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Intent intent = new Intent(this, FishingReceiver.class);
mPending = PendingIntent.getBroadcast(this, 0, intent, 0);
}
public void onResume() {
super.onResume();
mLocMan.addProximityAlert(37.94, 127.81, 500, -1, mPending);
}
public void onPause() {
super.onPause();
mLocMan.removeProximityAlert(mPending);
}
}
//FishingReceiver.java
package exam.location;
import android.content.*;
import android.location.*;
import android.widget.*;
public class FishingReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
boolean bEnter = intent.getBooleanExtra(
LocationManager.KEY_PROXIMITY_ENTERING, true);
Toast.makeText(context, bEnter ? "낚시하기 좋은 곳입니다.":"다른 곳으로 이동하세요.",
Toast.LENGTH_LONG).show();
}
}
mLocMan.addProximityAlert(37.94, 127.81, 500, -1, mPending);
이 메소드에 의해서 37.94 127.81좌표의 500미터 근방에 가면 낚시하기 좋은곳입니다.라는 토스트 메시지가 발생하고
아니라면 다른곳으로 이동하세요라는 토스트 메시지가 발생해야되는데...
에뮬로 돌려서 ddms로 좌표를 보내도 아무런 반응이 없네요...
소스를 이해하기도 좀 어렵네요...
혹시 이유를 아시면 댓글 부탁드려요ㅜㅜ
소스에 대한 설명도 부탁드리겠습니다ㅜㅜ
Action으로 매칭 시켜주세요
exam.location.ACTION_FISHING 이런식으로 하나 정의 하셔서 인텐트 보낼때 이 엑션을 넣어서 보내시고
브로드캐스트 리시버도 필터에 저 엑션을 추가하시면 됩니다.