後でテスト用のエリアに近接を設定しようとしています。これをonCreate
メインアクティビティのメソッドに追加しただけです。
public void onCreate(Bundle bndBundle) {
IntentFilter filter = new IntentFilter(WidgetService.ACTION_STOP_PROXIMITY);
registerReceiver(new ProximityIntentReceiver(), filter);
LocationManager locManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
Intent ittIntent = new Intent(this, ProximityIntentReceiver.class);
ittIntent.putExtra(WidgetService.KEY_STOP_IDENTIFIER, 1000);
PendingIntent pitIntent = PendingIntent.getBroadcast(this, 0, ittIntent, 0);
locManager.addProximityAlert(60.15769, 24.94150, 150, -1, pitIntent);
super.onCreate(bndBundle);
getActionBar().setDisplayHomeAsUpEnabled(false);
}
..そして、これが私が使用している単純なレシーバークラスです
public class ProximityIntentReceiver extends BroadcastReceiver {
private static final int NOTIFICATION_ID = 1000;
@Override
public void onReceive(Context context, Intent intent) {
String key = LocationManager.KEY_PROXIMITY_ENTERING;
Boolean entering = intent.getBooleanExtra(key, false);
if (entering) {
Log.d(getClass().getSimpleName(), "entering");
}
else {
Log.d(getClass().getSimpleName(), "exiting");
}
}
}
エミュレーターでこれをテストしていますが、DDMS コンソールを使用して電話の座標を手動で設定しても、まだログ メッセージが表示されません。
私のマニフェスト ファイルには特別なコードはありません。正しいアクセス許可を追加し、単純なアクティビティのコードを用意しました。サービスなどはありません。
StacKOverflow に関する一連の投稿を読みましたが、問題を解決できませんでした。スニペットに何か不足していますか?