- תחביר:
<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"
, ההודעה היחידה שתישלח למקלט השידור מקבלים הם אלה שנשלחים על ידי המערכת, רכיבים של אותה אפליקציה או אפליקציות עם אותו מזהה משתמש.אם לא צוין, ערך ברירת המחדל תלוי בשאלה אם מקלט השידור מכיל כוונה מסננים. אם המקבל מכיל לפחות מסנן Intent אחד, ערך ברירת המחדל הוא
"true"
אחרת, ערך ברירת המחדל הוא"false"
.המאפיין הזה הוא לא הדרך היחידה להגביל את החשיפה החיצונית של מקלט השידור. אפשר גם להשתמש בהרשאה כדי להגביל את הישויות החיצוניות שיכולות לשלוח אליה הודעות. מידע על המאפיין
permission
. android:icon
- סמל שמייצג את מקלט השידור. המאפיין הזה מוגדר
כהפניה למשאב שניתן להזזה שמכיל את הגדרת התמונה.
אם היא לא מוגדרת, יוצג הסמל שצוין עבור האפליקציה כולה
במקום זאת. לצפייה ב
<application>
המאפייןicon
של הרכיב.הסמל של מקלט השידור, בין שהוא מוגדר כאן או באמצעות רכיב
<application>
, הוא גם סמל ברירת מחדל לכל מסנני Intent של המקבל. לצפייה של רכיב<intent-filter>
icon
. android:label
- תווית קריאה למשתמש למקלט השידור. אם המאפיין הזה לא
התווית שהוגדרה לאפליקציה בכללותה
נעשה בו שימוש. הצגת הרכיב
<application>
label
.התווית של מקלט השידור, בין אם הוגדרה כאן או על ידי רכיב
<application>
, הוא גם תווית ברירת מחדל לכל מסנני Intent של הנמען. לצפייה של רכיב<intent-filter>
label
.התווית מוגדרת כהפניה למשאב של מחרוזת, כך אפשר להתאים אותו לשוק המקומי כמו מחרוזות אחרות בממשק המשתמש. עם זאת, לנוחיותכם במהלך הפיתוח של האפליקציה, אפשר להגדיר אותו גם כמחרוזת גולמית.
android:name
- שם המחלקה שבה מיישם את מקלט השידור, תת-מחלקה של
BroadcastReceiver
. זהו תווית מוגדרת במלואה שם הכיתה, למשל"com.example.project.ReportReceiver"
. אבל, לפעמים בתור קיצור, אם התו הראשון של השם הוא נקודה, לדוגמה,".ReportReceiver"
, הוא מצורף לשם החבילה שצוין ב את הרכיב<manifest>
.לאחר פרסום האפליקציה, אין לשנות את השם הזה, אלא אם מגדירים
android:exported="false"
.אין ברירת מחדל. צריך לציין את השם.
android:permission
- שם ההרשאה שנדרשת לשדרנים כדי לשלוח
הודעה למקלט השידור.
אם המאפיין הזה לא מוגדר, ההרשאה שהוגדרה על ידי
של רכיב
<application>
המאפייןpermission
רלוונטי למקלט השידור. אם אף אחד מהמאפיינים לא מוגדר, הנמען לא מוגן באמצעות הרשאה.למידע נוסף על הרשאות עיינו במאמר הרשאות בסקירה הכללית של קובץ המניפסט של האפליקציה. טיפים בנושא אבטחה.
android:process
- שם התהליך שבו פועל מקלט השידור.
בדרך כלל, כל הרכיבים של אפליקציה פועלים בתהליך ברירת המחדל שנוצר
עבור האפליקציה. יש לה שם זהה לחבילת האפליקציה.
של רכיב
<application>
אפשר להגדיר ערך אחר במאפייןprocess
ברירת מחדל לכל הרכיבים. אבל כל רכיב יכול לשנות את ברירת המחדל עם מאפייןprocess
משלו, שמאפשר לפזר בכמה תהליכים.אם השם שהוקצה למאפיין הזה מתחיל בנקודתיים (
:
), בתהליך פרטי לאפליקציה, נוצר בעת הצורך, מקלט השידור פועל בתהליך הזה.אם שם התהליך מתחיל בתו קטן, המקבל יפעל בתהליך גלובלי בשם זה, בתנאי שיש לו הרשאה לעשות זאת. כך אפשר לרכיבים באפליקציות שונות לשתף תהליך, וכך לצמצם שימוש במשאבים.
- הושקו ב:
- רמת API 1
<Receiver>
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 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"]]