- składnia:
<receiver android:directBootAware=["true" | "false"] android:enabled=["true" | "false"] android:exported=["true" | "false"] android:icon="drawable resource" android:label="string resource" android:name="string" android:permission="string" android:process="string" > ... </receiver>
- zawarte w:
<application>
- mogą zawierać:
<intent-filter>
<meta-data>
- description:
- Deklaruje odbiornik (
BroadcastReceiver
) podklasa jako jeden z komponentów aplikacji. Odbiorniki transmisji są włączone aplikacji odbierających intencje, które są transmitowane przez system lub przez inne nawet jeśli inne komponenty aplikacji nie są uruchomione.Są 2 sposoby poinformowanie systemu o odbiorniku. Po pierwsze: zadeklarować ją w pliku manifestu za pomocą tego elementu. Drugi to utworzenie do odbiornika w kodzie i rejestrować go za pomocą funkcji
Context.registerReceiver()
lub jedną z jej przeciążonych wersji.Więcej informacji o dynamicznym tworzeniu odbiorników znajdziesz w
BroadcastReceiver
zajęcia opis.Jeśli ten odbiornik obsługuje komunikaty spoza systemu, podaj wartość
android:exported
. Ustaw tę wartość na"true"
, jeśli chcesz, aby odbiornik mógł: odbiera komunikaty z innych aplikacji lub"false"
, jeśli tylko chcesz, aby odbiornik mógł odbierać komunikaty z Twojej własnej aplikacji.Nie musisz usuwać atrybutu
android:permission
, jeśli: została już przez Ciebie zadeklarowana.Ostrzeżenie: ogranicz liczbę transmisji odbiornikach ustawionych w aplikacji. Zbyt wiele odbiorników wpływają na wydajność aplikacji i żywotność baterii urządzenia. Aby uzyskać więcej informacji o interfejsach API, których możesz używać zamiast
BroadcastReceiver
zajęcia do planowania pracy w tle, zobacz Optymalizacja tła. - atrybuty:
android:directBootAware
Określa, czy odbiornik jest rozpoznany podczas rozruchu bezpośredniego, Dotyczy to tego, czy może ona zostać uruchomiona, zanim użytkownik odblokuje urządzenie.
Uwaga: w trakcie Bezpośredni rozruch, komunikat odbiornik w aplikacji ma dostęp wyłącznie do danych przechowywanych w pamięć chroniona na urządzeniu.
Wartość domyślna to
"false"
.android:enabled
- Określ, czy system może utworzyć wystąpienie odbiornika. Jest
"true"
, jeśli może być, lub"false"
, jeśli może być. Wartość domyślna jest"true"
.Element
<application>
ma swój własny element Atrybutenabled
, który ma zastosowanie do wszystkich i komponenty aplikacji, w tym odbiorniki.<application>
i Oba atrybuty<receiver>
muszą mieć wartość"true"
w przypadku wybierz odbiornik. Jeśli jeden z tych argumentów to"false"
, jest on wyłączona i nie można jej utworzyć. android:exported
- Określenie, czy odbiornik może odbierać wiadomości ze źródeł innych niż systemowe
poza jej zastosowaniem. W miarę możliwości jest to
"true"
, oraz"false"
jeśli nie. Jeśli"false"
, jedyne wiadomości odbiornika to te wysyłane przez system, składniki tej samej aplikacji o tym samym identyfikatorze użytkownika.Jeśli wartość domyślna nie została określona, zależy od tego, czy odbiornik zawiera intencję filtry. Jeśli odbiorca zawiera co najmniej 1 filtr intencji, wartość domyślna to
"true"
W przeciwnym razie domyślna wartość to"false"
.Ten atrybut nie jest jedynym sposobem ograniczenia zewnętrznej ekspozycji odbiornika. Możesz też użyć uprawnień, aby ograniczyć zewnętrzne podmioty, które mogą wysyłać do niego wiadomości. Zobacz atrybut
permission
. android:icon
- Ikona odbiornika. Ten atrybut jest ustawiony
jako odwołanie do zasobu rysowalnego zawierającego definicję obrazu.
Jeśli nie jest ustawiona, używana jest ikona określona dla całej aplikacji
. Zobacz
<application>
icon
tego elementu.Ikona odbiornika, ustawiona tutaj lub przez
<application>
, jest również domyślna ikona wszystkich filtrów intencji odbiorcy. Zobacz Element<intent-filter>
icon
. android:label
- Czytelna dla użytkownika etykieta odbiornika. Jeśli ten atrybut nie jest
etykietą ustawioną dla całej aplikacji jest
. Zobacz właściwości elementu
<application>
label
.Etykieta odbiornika, określona tutaj lub przez
<application>
, jest również etykieta domyślna wszystkich filtrów intencji odbiorcy. Zobacz Element<intent-filter>
label
.Etykieta jest ustawiona jako odniesienie do zasobu ciągu, więc i można go zlokalizować tak samo jak inne ciągi w interfejsie. Aby jednak zapewnić wygodę na etapie tworzenia aplikacji, można go też ustawić w postaci nieprzetworzonego ciągu znaków.
android:name
- Nazwa klasy, która implementuje odbiornik (podklasa)
BroadcastReceiver
To jest w pełni kwalifikowany nazwę klasy, na przykład"com.example.project.ReportReceiver"
. Pamiętaj jednak: jako skrótu, jeśli pierwszym znakiem nazwy jest kropka, np.".ReportReceiver"
, jest dołączony do nazwy pakietu określonej w polu element<manifest>
.Po opublikowaniu aplikacji nie zmień tę nazwę, chyba że ustawisz
android:exported="false"
.Nie ma wartości domyślnej. Musisz podać nazwę.
android:permission
- Nazwa uprawnienia, którego nadawcy potrzebują, aby wysłać
do odbiornika.
Jeśli ten atrybut nie jest skonfigurowany, uprawnienia określone przez
Element
<application>
Stosowany jest atrybutpermission
do odbiornika. Jeśli żaden z tych atrybutów nie jest ustawiony, odbiorca nie jest chronione uprawnieniami.Więcej informacji o uprawnieniach: Uprawnienia w omówieniu pliku manifestu aplikacji oraz Wskazówki dotyczące bezpieczeństwa
android:process
- Nazwa procesu, w którym działa odbiornik.
Normalnie wszystkie komponenty aplikacji są uruchamiane w procesie domyślnym
dla danej aplikacji. Ma taką samą nazwę jak pakiet aplikacji.
Element
<application>
Atrybutprocess
może ustawiać inne wartości domyślny dla wszystkich komponentów. Każdy komponent może jednak zastąpić komponent domyślny z własnym atrybutemprocess
, który umożliwia rozpowszechnianie do zastosowania w wielu procesach.Jeśli nazwa przypisana do tego atrybutu zaczyna się od dwukropka (
:
), nowy atrybut prywatny do aplikacji i tworzony, gdy jest potrzebny, działa w nim odbiornik.Jeśli nazwa procesu zaczyna się od małej litery, odbiorca działa w globalnym procesie dotyczącym tej nazwy, o ile ma do tego uprawnienia. Umożliwia to komponentom w różnych aplikacjach współużytkowanie procesu, co zmniejsza wykorzystanie zasobów.
- wprowadzone w:
- Poziom API 1
<Odbiorca>
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-27 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-07-27 UTC."],[],[],null,["# <receiver\u003e\n\nsyntax:\n:\n\n ```xml\n \u003creceiver android:directBootAware=[\"true\" | \"false\"]\n android:enabled=[\"true\" | \"false\"]\n android:exported=[\"true\" | \"false\"]\n android:icon=\"drawable resource\"\n android:label=\"string resource\"\n android:name=\"string\"\n android:permission=\"string\"\n android:process=\"string\" \u003e\n ...\n \u003c/receiver\u003e\n ```\n\ncontained in:\n: [\u003capplication\u003e](/guide/topics/manifest/application-element)\n\ncan contain:\n: [\u003cintent-filter\u003e](/guide/topics/manifest/intent-filter-element)\n\n [\u003cmeta-data\u003e](/guide/topics/manifest/meta-data-element)\n\ndescription:\n: Declares a broadcast receiver, a [BroadcastReceiver](/reference/android/content/BroadcastReceiver)\n subclass, as one of the application's components. Broadcast receivers enable\n applications to receive intents that are broadcast by the system or by other\n applications, even when other components of the application aren't running.\n\n\n There are two ways to make a broadcast receiver known to the system. One is to\n declare it in the manifest file with this element. The other is to create\n the receiver dynamically in code and register it with the\n [Context.registerReceiver()](/reference/android/content/Context#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter))\n method or one of its overloaded versions.\n\n\n For more information about how to dynamically create receivers, see the\n [BroadcastReceiver](/reference/android/content/BroadcastReceiver) class\n description.\n\n\n If this receiver handles non-system broadcasts, specify a value for `android:exported`.\n Set this value to `\"true\"` if you want your receiver to be able to\n receiver broadcasts from other applications or `\"false\"` if you only\n want your receiver to be able to receive broadcasts from your own app.\n\n\n You don't have to remove the `android:permission` attribute if you\n already declared it.\n\n\n **Warning:** Limit how many broadcast\n receivers you set in your app. Having too many broadcast receivers can\n affect your app's performance and the battery life of users' devices.\n For more information about APIs you can use instead of the\n `BroadcastReceiver` class for scheduling background work, see\n [Background optimization](/topic/performance/background-optimization).\n\nattributes:\n:\n\n `android:directBootAware`\n\n : Whether the broadcast receiver is *Direct-Boot aware*, that\n is, whether it can run before the user unlocks the device.\n\n **Note:** During\n [Direct Boot](/training/articles/direct-boot), a broadcast\n receiver in your application can only access the data that is stored in\n *device protected* storage.\n\n The default value is `\"false\"`.\n\n `android:enabled`\n : Whether the broadcast receiver can be instantiated by the system. It's\n `\"true\"` if it can be, and `\"false\"` if not. The default value\n is `\"true\"`.\n\n\n The [\u003capplication\u003e](/guide/topics/manifest/application-element) element has its own\n [enabled](/guide/topics/manifest/application-element#enabled) attribute that applies to all\n application components, including broadcast receivers. The\n `\u003capplication\u003e` and\n `\u003creceiver\u003e` attributes must both be `\"true\"` for\n the broadcast receiver to be enabled. If either is `\"false\"`, it's\n disabled and can't be instantiated.\n\n `android:exported`\n : Whether the broadcast receiver can receive messages from non-system sources\n outside its application. It's `\"true\"` if it can, and `\"false\"`\n if not. If `\"false\"`, the only messages the broadcast receiver\n receives are those sent by the system, components of the same application, or applications\n with the same user ID.\n\n\n If unspecified, the default value depends on whether the broadcast receiver contains intent\n filters. If the receiver contains at least one intent filter, then the default value is\n `\"true\"`. Otherwise, the default value is `\"false\"`.\n\n\n This attribute is not the only way to limit a broadcast receiver's external exposure.\n You can also use a permission to limit the external entities that can send it messages.\n See the [permission](/guide/topics/manifest/receiver-element#prmsn) attribute.\n\n `android:icon`\n : An icon representing the broadcast receiver. This attribute is set\n as a reference to a drawable resource containing the image definition.\n If it isn't set, the icon specified for the application as a whole is used\n instead. See the [\u003capplication\u003e](/guide/topics/manifest/application-element)\n element's [icon](/guide/topics/manifest/application-element#icon) attribute.\n\n\n The broadcast receiver's icon, whether set here or by the\n `\u003capplication\u003e` element, is also the\n default icon for all the receiver's intent filters. See the\n [\u003cintent-filter\u003e](/guide/topics/manifest/intent-filter-element) element's\n [icon](/guide/topics/manifest/intent-filter-element#icon) attribute.\n\n `android:label`\n : A user-readable label for the broadcast receiver. If this attribute isn't\n set, the label set for the application as a whole is\n used instead. See the [\u003capplication\u003e](/guide/topics/manifest/application-element) element's\n [label](/guide/topics/manifest/application-element#label) attribute.\n\n\n The broadcast receiver's label, whether set here or by the\n `\u003capplication\u003e` element, is also the\n default label for all the receiver's intent filters. See the\n [\u003cintent-filter\u003e](/guide/topics/manifest/intent-filter-element) element's\n [label](/guide/topics/manifest/intent-filter-element#label) attribute.\n\n\n The label is set as a reference to a string resource, so that\n it can be localized like other strings in the user interface.\n However, as a convenience while you're developing the application,\n it can also be set as a raw string.\n\n `android:name`\n : The name of the class that implements the broadcast receiver, a subclass of\n [BroadcastReceiver](/reference/android/content/BroadcastReceiver). This is a fully qualified\n class name, such as `\"com.example.project.ReportReceiver\"`. However,\n as a shorthand, if the first character of the name is a period, for example,\n `\".ReportReceiver\"`, it is appended to the package name specified in\n the [\u003cmanifest\u003e](/guide/topics/manifest/manifest-element) element.\n\n Once you publish your application, [don't\n change this name](http://android-developers.blogspot.com/2011/06/things-that-cannot-change.html), unless you set [android:exported](#exported)`=\"false\"`.\n\n\n There is no default. The name must be specified.\n\n `android:permission`\n : The name of a permission that broadcasters need in order to send a\n message to the broadcast receiver.\n If this attribute isn't set, the permission set by the\n [\u003capplication\u003e](/guide/topics/manifest/application-element) element's\n [permission](/guide/topics/manifest/application-element#prmsn) attribute applies\n to the broadcast receiver. If neither attribute is set, the receiver\n isn't protected by a permission.\n\n\n For more information about permissions, see the\n [Permissions](/guide/topics/manifest/manifest-intro#perms)\n section in the app manifest overview and\n [Security tips](/guide/topics/security/security).\n\n `android:process`\n\n : The name of the process in which the broadcast receiver runs. Normally, all components of an application run in the default process created for the application. It has the same name as the application package.\u003cbr /\u003e\n\n The\n [\u003capplication\u003e](/guide/topics/manifest/application-element) element's\n [process](/guide/topics/manifest/application-element#proc) attribute can set a different\n default for all components. But each component can override the default\n with its own `process` attribute, letting you spread your\n application across multiple processes.\n\n\n If the name assigned to this attribute begins with a colon (`:`), a new\n process, private to the application, is created when it's needed, and\n the broadcast receiver runs in that process.\n\n\n If the process name begins with a lowercase character, the receiver runs\n in a global process of that name, provided that it has permission to do so.\n This lets components in different applications share a process, reducing\n resource usage.\n\nintroduced in:\n: API level 1"]]