我正在開發帶有提醒的按時間和按位置的ToDo應用程序,而且事情是我給了用戶選擇if他希望提醒按位置提醒他何時輸入的位置或何時他退出的位置。 我該怎麼做?Android:如何設置接近警報僅在退出或僅在進入位置時觸發
我瞭解KEY_PROXIMITY_ENTERING但我不知道如何使用它 請幫助... thanx提前
我正在開發帶有提醒的按時間和按位置的ToDo應用程序,而且事情是我給了用戶選擇if他希望提醒按位置提醒他何時輸入的位置或何時他退出的位置。 我該怎麼做?Android:如何設置接近警報僅在退出或僅在進入位置時觸發
我瞭解KEY_PROXIMITY_ENTERING但我不知道如何使用它 請幫助... thanx提前
的KEY_PROXIMITY_ENTERING是通常用於確定設備是否進入或退出。
你應該先註冊到的LocationManager
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Intent intent = new Intent(Constants.ACTION_PROXIMITY_ALERT);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
locationManager.addProximityAlert(location.getLatitude(),
location.getLongitude(), location.getRadius(), -1, pendingIntent);
的的PendingIntent將會被用來生成一個Intent檢測到從警報區域進入或退出時觸發。 你應該定義廣播接收器接收從發送的LocationManager廣播:
public class YourReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final String key = LocationManager.KEY_PROXIMITY_ENTERING;
final Boolean entering = intent.getBooleanExtra(key, false);
if (entering) {
Toast.makeText(context, "entering", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "exiting", Toast.LENGTH_SHORT).show();
}
}
}
然後在你的清單註冊的接收器。
<receiver android:name="yourpackage.YourReceiver " >
<intent-filter>
<action android:name="ACTION_PROXIMITY_ALERT" />
</intent-filter>
</receiver>
你可以在這裏找到一個很好的例子: http://www.java2s.com/Code/Android/Core-Class/ProximityAlertDemo.htm
另一個問題 - 我的接收器已經通過時間**廣播處理**提醒。我怎樣才能定義哪個提醒觸發了這個動作?他們兩個都是從同一個班上被解僱的 - @Jermaine Xu – Daniel 2013-03-04 07:41:02
順便說一句,關於主要問題的答案。似乎這是答案 - @Jermaine Xu – Daniel 2013-03-04 07:44:10
我想你想要intent.getAction(),不是嗎? – StarPinkER 2013-03-04 07:50:06