У меня есть несколько намерений, которые активность отправляет на обслуживание.Все они зарегистрированы в манифесте:
<service android:name=".location.LocationService" android:label="@string/location_service_started">
<intent-filter>
<action android:name="@string/location_service_set" />
<action android:name="@string/location_service_start" />
<action android:name="@string/location_service_stop" />
</intent-filter>
</service>
Но получаются только намерения location_service_start и location_service_stop.Что может быть причиной?Вот код моего получателя:
private BroadcastReceiver LocationServiceReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(getString(R.string.location_service_stop)))
{
showMessage("stop");
}
if(intent.getAction().equals(getString(R.string.location_service_start)))
{
showMessage("start");
}
if(intent.getAction().equals(getString(R.string.location_service_set)))
{
showAlertBox("set");
}
}
};
Так что я никогда не вижу сообщения "set".Я даже пытался поместить sendBroadcast для «start» и «set» сообщений в одном месте, но все по-прежнему.«start» - «OK», «set» - никогда не принимается.
Функции, которые запускают намерения:
protected void start()
{
Intent intent = new Intent(getString(R.string.location_service_start));
getApplicationContext().sendBroadcast(intent);
}
protected void set(double lat, double lon, double rad)
{
Intent intent = new Intent(getString(R.string.location_service_set));
intent.putExtra("lat", lat);
intent.putExtra("lon", lon);
intent.putExtra("rad", rad);
getApplicationContext().sendBroadcast(intent);
}
Обе команды отправляются правильно, без ошибок, действия верны.
UPD:
О, моя вина.Я забыл добавить filter.addAction ... для новых намерений.Мне жаль.Но ответы были действительно полезны!Спасибо!