- نحو:
<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>
- موجود در:
-
<application>
- می تواند شامل:
-
<intent-filter>
<meta-data>
- توضیحات:
- یک گیرنده پخش، یک زیرکلاس
BroadcastReceiver
، را به عنوان یکی از اجزای برنامه اعلام می کند. گیرندههای پخش، برنامهها را قادر میسازند تا مقاصدی را دریافت کنند که توسط سیستم یا سایر برنامهها پخش میشوند، حتی زمانی که سایر اجزای برنامه در حال اجرا نیستند.دو راه برای شناخته شدن یک گیرنده پخش به سیستم وجود دارد. یکی این است که آن را در فایل مانیفست با این عنصر اعلام کنید. دیگری ایجاد گیرنده به صورت پویا در کد و ثبت آن با متد
Context.registerReceiver()
یا یکی از نسخه های بارگذاری شده آن است.برای اطلاعات بیشتر در مورد نحوه ایجاد گیرنده به صورت پویا، به توضیحات کلاس
BroadcastReceiver
مراجعه کنید.اگر این گیرنده پخشهای غیر سیستمی را مدیریت میکند، مقداری را برای
android:exported
مشخص کنید. اگر میخواهید گیرندهتان بتواند پخشهای دریافتکننده از برنامههای دیگر را داشته باشد، این مقدار را روی"true"
یا اگر میخواهید گیرنده شما فقط قادر به دریافت پخش از برنامه خودتان باشد"false"
را تنظیم کنید.اگر قبلاً مشخصه
android:permission
را اعلام کرده اید، لازم نیست آن را حذف کنید.هشدار: تعداد گیرنده های پخشی را که در برنامه خود تنظیم می کنید محدود کنید. داشتن گیرنده های پخش بیش از حد می تواند بر عملکرد برنامه شما و عمر باتری دستگاه های کاربران تأثیر بگذارد. برای اطلاعات بیشتر در مورد APIها میتوانید به جای کلاس
BroadcastReceiver
برای زمانبندی کار پسزمینه استفاده کنید، به بهینهسازی پسزمینه مراجعه کنید. - صفات:
-
android:directBootAware
آیا گیرنده پخش از Direct-Boot آگاه است یا خیر، یعنی می تواند قبل از باز کردن قفل دستگاه توسط کاربر اجرا شود یا خیر.
توجه: در طول راهاندازی مستقیم ، یک گیرنده پخش در برنامه شما فقط میتواند به دادههایی که در فضای ذخیرهسازی محافظت شده دستگاه ذخیره شدهاند دسترسی داشته باشد.
مقدار پیش فرض
"false"
است.-
android:enabled
- آیا گیرنده پخش می تواند توسط سیستم نمونه برداری شود یا خیر. اگر می تواند
"true"
است و اگر نه"false"
. مقدار پیش فرض"true"
است.عنصر
<application>
ویژگیenabled
خود را دارد که برای همه اجزای برنامه از جمله گیرنده های پخش اعمال می شود. ویژگی های<application>
و<receiver>
هر دو باید"true"
باشند تا گیرنده پخش فعال شود. اگر هر کدام"false"
باشد، غیرفعال است و نمیتوان آن را نمونهسازی کرد. -
android:exported
- آیا گیرنده پخش می تواند پیام ها را از منابع غیر سیستمی خارج از برنامه خود دریافت کند یا خیر. اگر بتواند
"true"
است و اگر نه"false"
. اگر"false"
باشد، تنها پیامهایی که گیرنده پخش دریافت میکند پیامهایی است که توسط سیستم، اجزای همان برنامه یا برنامههایی با شناسه کاربری یکسان ارسال میشود.اگر مشخص نباشد، مقدار پیشفرض به این بستگی دارد که گیرنده پخش دارای فیلترهای هدف باشد یا خیر. اگر گیرنده دارای حداقل یک فیلتر هدف باشد، مقدار پیشفرض
"true"
است. در غیر این صورت، مقدار پیش فرض"false"
است.این ویژگی تنها راه برای محدود کردن نوردهی خارجی گیرنده پخش نیست. همچنین میتوانید از یک مجوز برای محدود کردن نهادهای خارجی که میتوانند به آن پیام ارسال کنند، استفاده کنید. ویژگی
permission
را ببینید. -
android:icon
- نمادی که گیرنده پخش را نشان می دهد. این ویژگی به عنوان یک مرجع به یک منبع قابل ترسیم حاوی تعریف تصویر تنظیم می شود. اگر تنظیم نشده باشد، به جای آن از نماد مشخص شده برای برنامه به طور کلی استفاده می شود. ویژگی
icon
عنصر<application>
را ببینید.نماد گیرنده پخش، چه در اینجا تنظیم شده باشد و چه توسط عنصر
<application>
، همچنین نماد پیش فرض تمام فیلترهای هدف گیرنده است. ویژگیicon
عنصر<intent-filter>
را ببینید. -
android:label
- یک برچسب قابل خواندن توسط کاربر برای گیرنده پخش. اگر این ویژگی تنظیم نشده باشد، به جای آن از برچسب مجموعه برای برنامه به طور کلی استفاده می شود. ویژگی
label
عنصر<application>
را ببینید.برچسب گیرنده پخش، چه در اینجا تنظیم شده باشد و چه توسط عنصر
<application>
، همچنین برچسب پیش فرض برای تمام فیلترهای هدف گیرنده است. ویژگیlabel
عنصر<intent-filter>
را ببینید.برچسب به عنوان یک مرجع به یک منبع رشته تنظیم می شود، به طوری که می توان آن را مانند سایر رشته ها در رابط کاربری محلی کرد. با این حال، به عنوان یک راحتی در هنگام توسعه برنامه، می توان آن را به عنوان یک رشته خام نیز تنظیم کرد.
-
android:name
- نام کلاسی که گیرنده پخش را پیادهسازی میکند، زیرکلاس
BroadcastReceiver
. این یک نام کلاس کاملاً واجد شرایط است، مانند"com.example.project.ReportReceiver"
. با این حال، به عنوان خلاصه، اگر اولین کاراکتر نام یک نقطه باشد، به عنوان مثال،".ReportReceiver"
، به نام بسته مشخص شده در عنصر<manifest>
اضافه می شود.هنگامی که برنامه خود را منتشر کردید، این نام را تغییر ندهید ، مگر اینکه
android:exported ="false"
را تنظیم کنید.هیچ پیش فرضی وجود ندارد. نام باید مشخص شود.
-
android:permission
- نام مجوزی که پخش کننده ها برای ارسال پیام به گیرنده پخش نیاز دارند. اگر این ویژگی تنظیم نشده باشد، مجوز تنظیم شده توسط ویژگی
permission
عنصر<application>
برای گیرنده پخش اعمال می شود. اگر هیچ یک از ویژگی ها تنظیم نشده باشد، گیرنده توسط یک مجوز محافظت نمی شود.برای اطلاعات بیشتر درباره مجوزها، به بخش مجوزها در نمای کلی مانیفست برنامه و نکات امنیتی مراجعه کنید.
-
android:process
- نام فرآیندی که گیرنده پخش در آن اجرا می شود. به طور معمول، تمام اجزای یک برنامه در فرآیند پیش فرض ایجاد شده برای برنامه اجرا می شوند. این همان نام بسته برنامه است.
ویژگی
process
عنصر<application>
میتواند پیشفرض متفاوتی را برای همه مؤلفهها تنظیم کند. اما هر مؤلفه میتواند پیشفرض را با ویژگیprocess
خود لغو کند و به شما امکان میدهد برنامه خود را در چندین فرآیند پخش کنید.اگر نام تخصیص داده شده به این ویژگی با یک دونقطه (
:
) شروع شود، یک فرآیند جدید، خصوصی برای برنامه، در صورت نیاز ایجاد می شود و گیرنده پخش در آن فرآیند اجرا می شود.اگر نام فرآیند با یک کاراکتر کوچک شروع شود، گیرنده در یک فرآیند سراسری با آن نام اجرا میشود، مشروط بر اینکه مجوز این کار را داشته باشد. این به اجزای برنامه های مختلف اجازه می دهد تا فرآیندی را به اشتراک بگذارند و مصرف منابع را کاهش دهد.
-
- معرفی شده در:
- API سطح 1
<گیرنده>
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],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"]]