- بناء الجملة:
<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>
- description:
- يذكر جهاز استقبال البث،
BroadcastReceiver
الفئة الفرعية، كأحد مكونات التطبيق. تفعيل أجهزة استقبال البث التطبيقات لتلقي الأهداف التي بثها النظام أو عن طريق التطبيقات، حتى في حالة عدم تشغيل المكونات الأخرى للتطبيق.هناك طريقتان لإعلام النظام بجهاز استقبال البث. الأول هو تعريفه في ملف البيان باستخدام هذا العنصر. والآخر هو إنشاء جهاز الاستقبال ديناميكيًا في رمز برمجي وتسجيله
Context.registerReceiver()
أو أحد إصداراته المحملة بشكل زائد.لمزيد من المعلومات عن طريقة الإنشاء الديناميكي لأجهزة الاستقبال، يُرجى الاطّلاع على صف واحد (
BroadcastReceiver
) الوصف.إذا كان هذا المُستلِم يتعامل مع عمليات بث غير تابعة للنظام، حدِّد قيمة للحقل "
android:exported
". اضبط هذه القيمة على"true"
إذا أردت أن يتمكّن المُستلِم من أجهزة الاستقبال من تطبيقات أخرى أو"false"
إذا كنت تريد أن يتمكن المتلقي من تلقي عمليات بث من تطبيقك.لن تضطر إلى إزالة السمة
android:permission
إذا قد أعلنت عنه بالفعل.تحذير: يجب تحديد عدد مرات البث أجهزة الاستقبال التي تحدّدها في تطبيقك. يمكن أن يؤدي وجود عدد كبير جدًا من مستقبلات البث تؤثر في أداء تطبيقك وعمر بطارية المستخدمين الأجهزة. لمزيد من المعلومات حول واجهات برمجة التطبيقات، يمكنك استخدام بدلاً من صف واحد (
BroadcastReceiver
) لجدولة العمل في الخلفية، يُرجى الاطّلاع على تحسين الخلفية: - :
android:directBootAware
سواء كان مستقبل البث مع العلم بدء التشغيل المباشر، سيتم هو، ما إذا كان يمكن تشغيله قبل أن يفتح المستخدم قفل الجهاز.
ملاحظة: خلال التشغيل المباشر، بث يمكن للمستلم في تطبيقك الدخول فقط إلى البيانات المخزنة في حماية الجهاز
القيمة التلقائية هي
"false"
.android:enabled
- ما إذا كان بإمكان النظام إنشاء مثيل لجهاز استقبال البث. من المهم
"true"
إذا كان ذلك ممكنًا، و"false"
إذا لم يكن ممكنًا. القيمة التلقائية"true"
.العنصر
<application>
له خاصية سمةenabled
التي تنطبق على الكل مكونات التطبيق، بما في ذلك أجهزة استقبال البث. تشير رسالة الأشكال البيانية<application>
و يجب أن تكون سمتا<receiver>
"true"
من أجل تمكين مستقبل البث. إذا كانت قيمة أي منهما هي"false"
، تكون غير مفعّل ولا يمكن إنشاء مثيل له. android:exported
- ما إذا كان بإمكان مستقبل البث استلام رسائل من مصادر غير النظام
خارج نطاق تطبيقها. تبلغ درجة الحرارة
"true"
إذا أمكن، و"false"
. إن لم يكن كذلك. إذا كانت"false"
، هي الرسائل الوحيدة التي المستلمة هي تلك التي يرسلها النظام أو مكونات التطبيق نفسه أو التطبيقات برقم تعريف المستخدم نفسه.في حال عدم تحديد القيمة، ستعتمد القيمة التلقائية على ما إذا كان مستقبل البث يتضمّن intent. والفلاتر. إذا كان المُستلِم يحتوي على فلتر أهداف واحد على الأقل، فإن القيمة التلقائية هي
"true"
وبخلاف ذلك، تكون القيمة التلقائية هي"false"
.هذه السمة ليست الطريقة الوحيدة لتقييد التعرّض الخارجي لاستقبال البث. يمكنك أيضًا استخدام إذن لتقييد الكيانات الخارجية التي يمكنها إرسال الرسائل. اطّلِع على السمة
permission
. android:icon
- رمز يمثّل جهاز استقبال البث تم ضبط هذه السمة.
كمرجع لمورد قابل للرسم يحتوي على تعريف الصورة.
إذا لم يتم ضبطه، يتم استخدام الرمز المحدّد للتطبيق بالكامل
بدلاً من ذلك. يمكنك الاطّلاع على
<application>
. السمةicon
للعنصر.رمز مستلم البث، سواء تم تعيينه هنا أو بواسطة عنصر
<application>
، هو أيضًا الرمز التلقائي لكل فلاتر الأهداف لدى المستلِم. يمكنك الاطّلاع على عنصر<intent-filter>
السمةicon
. android:label
- تصنيف سهل القراءة للمستخدم لمستقبِل البث وإذا لم تكن هذه السمة
المجموعة، يتم تعيين التصنيف للتطبيق ككل
استخدامه بدلاً من ذلك. إليك العنصر
<application>
السمةlabel
.تصنيف مستلم البث، سواء تم ضبطه هنا أو بواسطة عنصر
<application>
، هو أيضًا تصنيف تلقائي لجميع فلاتر الأهداف لدى المُستلِم. يمكنك الاطّلاع على عنصر<intent-filter>
السمةlabel
.يتم تعيين التسمية كمرجع لمورد السلسلة، بحيث يمكن ترجمتها مثل السلاسل الأخرى في واجهة المستخدم. ومع ذلك، ولتسهيل الأمر أثناء تطوير التطبيق، ويمكن أيضًا ضبطه كسلسلة أولية.
android:name
- اسم الفئة التي تنفذ مستقبل البث، وهو فئة فرعية من
BroadcastReceiver
هذا فريق مؤهل بالكامل اسم الفئة، مثل"com.example.project.ReportReceiver"
. ومع ذلك، كاختصار، إذا كان الحرف الأول من الاسم نقطة، على سبيل المثال،".ReportReceiver"
، سيتم إلحاقه باسم الحزمة المحدّد في العنصر<manifest>
.بعد نشر التطبيق، لا تغيير هذا الاسم، ما لم يتم ضبط
android:exported="false"
.لا يوجد إعداد افتراضي. يجب تحديد الاسم.
android:permission
- اسم الإذن الذي تحتاجه جهات البث لإرسال
إلى مستقبل البث.
إذا لم يتم ضبط هذه السمة، سيتم منح الإذن الذي تحدّده السمة
عنصر
<application>
تنطبق السمةpermission
إلى مستقبل البث. إذا لم يتم تعيين أي من السمتين، فإن المستلِم غير محمي بإذن.لمزيد من المعلومات حول الأذونات، يمكنك الاطّلاع على الأذونات في نظرة عامة على بيان التطبيق نصائح الأمان:
android:process
- اسم العملية التي يتم فيها تشغيل جهاز استقبال البث.
عادةً، تعمل جميع مكونات التطبيق في العملية الافتراضية التي يتم إنشاؤها
للتطبيق. تحمل نفس اسم حزمة التطبيق.
تشير رسالة الأشكال البيانية عنصر
<application>
يمكن للسمةprocess
ضبط قيمة مختلفة افتراضيًا لجميع المكونات. ولكن يمكن لكل مكون إلغاء الإعداد الافتراضي مع سمةprocess
الخاصة بها، ما يتيح لك نشر تطبيقها عبر عمليات متعددة.إذا كان الاسم المعيّن لهذه السمة يبدأ بنقطتين (
:
)، تكون قيمة عملية خاصة بالتطبيق، عند الحاجة، يعمل مستقبل البث في هذه العملية.إذا كان اسم العملية يبدأ بحرف صغير، يبدأ المُستلِم في عملية عمومية بهذا الاسم، بشرط أن يكون لديه إذن بالقيام بذلك. وهذا يتيح للمكونات في التطبيقات المختلفة مشاركة عملية، مما يقلل استخدام الموارد.
- تم تقديمها في:
- المستوى 1 من واجهة برمجة التطبيقات
<Recipientr>
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],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"]]