๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ

[Android] AndroidManifest <receiver>

<receiver>

developer.android.com/guide/topics/manifest/receiver-element?hl=ko

 

 |  Android ๊ฐœ๋ฐœ์ž  |  Android Developers

broadcast receiver(BroadcastReceiver ์„œ๋ธŒํด๋ž˜์Šค)๋ฅผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ตฌ์„ฑ์š”์†Œ ์ค‘ ํ•˜๋‚˜๋กœ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. broadcast receiver๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค๋ฅธ ๊ตฌ์„ฑ์š”์†Œ๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์„ ๋•Œ๋„ ์‹œ์Šคํ…œ์ด๋‚˜ ๋‹ค๋ฅธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋ธŒ

developer.android.com

<application>
    ...
    <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">
                  
        ...
    
        <intent-filter>...</intent-filter>
        <meta-data>...</meta-data>
    </receiver>
    ...
</application>

 

broadcast receiver(BroadcastReceiver ์„œ๋ธŒํด๋ž˜์Šค)๋ฅผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ component๋กœ ์„ ์–ธํ•œ๋‹ค.

broadcast receiver๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋˜๊ณ  ์žˆ์ง€ ์•Š์„ ๋–„์—๋„ ์‹œ์Šคํ…œ์ด๋‚˜ ๋‹ค๋ฅธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋ธŒ๋กœ๋“œ์ผ€์ŠคํŒ…ํ•˜๋Š” ์ธํ…ํŠธ๋ฅผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ˆ˜์‹ ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

broadcast receiver๋ฅผ ์‹œ์Šคํ…œ์— ์•Œ๋ฆฌ๋Š” ๋ฐฉ๋ฒ• ๋‘ ๊ฐ€์ง€ ์ค‘ ํ•˜๋‚˜๊ฐ€ manifest ํŒŒ์ผ์— broadcast receiver๋ฅผ ์„ ์–ธํ•˜๋Š” ๊ฒƒ. ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์€ ์ฝ”๋“œ์—์„œ ๋“ฑ๋กํ•˜๋Š” ๋ฐฉ์‹.

 

์†์„ฑ

android:directBootAware

broadcast receiver๊ฐ€ ์ง์ ‘ ๋ถ€ํŒ…์„ ์ธ์‹(direct-boot aware)ํ•˜๋Š”์ง€ ์—ฌ๋ถ€. ์‚ฌ์šฉ์ž๊ฐ€ ๊ธฐ๊ธฐ๋ฅผ ์ž ๊ธˆ ํ•ด์ œ ํ•˜๊ธฐ ์ „์— ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š”์ง€์˜ ์—ฌ๋ถ€. Lock ์ƒํƒœ์—์„œ ์•ฑ์ด ๋™์ž‘ํ•  ๊ฒƒ์ธ์ง€์˜ ์—ฌ๋ถ€.

๊ธฐ๋ณธ๊ฐ’์€ false

 

android:enabled

์‹œ์Šคํ…œ์—์„œ broadcast receiver๋ฅผ ์ธ์Šคํ„ด์Šคํ™”ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์—ฌ๋ถ€. ํ•  ์ˆ˜ ์žˆ์œผ๋ฉด true, ํ•  ์ˆ˜ ์—†์œผ๋ฉด false.

<application>์˜ enabled ์†์„ฑ๋„ true์—ฌ์•ผ์ง€, <receiver>์˜ enabled true ์†์„ฑ์ด ์œ ํšจํ•˜๋‹ค.

 

android:exported

broadcast receiver์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์™ธ๋ถ€๋กœ๋ถ€ํ„ฐ ์˜ค๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์ˆ˜์‹ ํ•  ์ˆ˜ ์žˆ๋Š”์ง€์˜ ์—ฌ๋ถ€. 

true๋Š” ์ˆ˜์‹  ๊ฐ€๋Šฅ. false๋Š” ๋™์ผํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด๋‚˜ ๋™์ผํ•œ user ID๋ฅผ ๊ฐ€์ง„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ณด๋‚ธ ๋ฉ”์‹œ์ง€๋งŒ ์ˆ˜์‹  ๊ฐ€๋Šฅ.

๊ธฐ๋ณธ๊ฐ’์€ ์ธํ…ํŠธ ํ•„ํ„ฐ๊ฐ€ ์—†์œผ๋ฉด false, ์žˆ์œผ๋ฉด true. ์ธํ…ํŠธ ํ•„ํ„ฐ๊ฐ€ ํ•˜๋‚˜ ์ด์ƒ ์žˆ๋‹ค๋Š” ๊ฒƒ์€ broadcast receiver๊ฐ€ ์‹œ์Šคํ…œ์ด๋‚˜ ๋‹ค๋ฅธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋ธŒ๋กœ๋“œ์บ์ŠคํŒ…ํ•˜๋Š” ์ธํ…ํŠธ๋ฅผ ์ˆ˜์‹ ํ•˜๋ ค๊ณ  ํ•œ๋‹ค๋Š” ์˜๋ฏธ. ์ธํ…ํŠธ ํ•„ํ„ฐ๊ฐ€ ์—†๋‹ค๋ฉด ์ •ํ™•ํ•œ ํด๋ž˜์Šค ์ด๋ฆ„์„ ์ง€์ •ํ•˜๋Š” ์ธํ…ํŠธ ๊ฐ์ฒด๋งŒ broadcast receiver๋ฅผ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ, receiver๊ฐ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋‚ด๋ถ€์—์„œ๋งŒ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ์˜๋ฏธ.

 permission ์†์„ฑ์œผ๋กœ exported์™€ ๋น„์Šทํ•œ ํšจ๊ณผ๋ฅผ ์ค„ ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค.

android:icon

broadcast receiver๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์•„์ด์ฝ˜. drawable resource ์ฐธ์กฐ๋กœ ์„ค์ •๋˜์–ด์•ผ ํ•œ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ <application>์˜ icon ๊ฐ’.

 

android:label

์‚ฌ์šฉ์ž๊ฐ€ broadcast์— ๋Œ€ํ•ด ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ๋ผ๋ฒจ. ์ด ์†์„ฑ์ด ์„ค์ •๋˜์ง€ ์•Š์œผ๋ฉด <application>์˜ label ๊ฐ’์ด ์‚ฌ์šฉ๋œ๋‹ค.

broadcast receiver์˜ label์€ receiver ์ธํ…ํŠธ ํ•„ํ„ฐ์˜ ๊ธฐ๋ณธ ๋ผ๋ฒจ์ด ๋œ๋‹ค.

 

ํ˜„์ง€ํ™”๋  ์ˆ˜ ์žˆ๊ฒŒ ๋ฌธ์ž์—ด ๋ฆฌ์†Œ์Šค ์ฐธ์กฐ๋กœ ์„ค์ •๋˜์–ด์•ผ ํ•จ. ๊ฐœ๋ฐœ ํŽธ์˜๋ฅผ ์œ„ํ•ด ์›์‹œ ๋ฌธ์ž์—ด๋กœ ์„ค์ • ๊ฐ€๋Šฅ.

 

android:name

broadcast receiver์˜ ํด๋ž˜์Šค ์ด๋ฆ„. BroadcastReceiver ํด๋ž˜์Šค์˜ ์„œ๋ธŒํด๋ž˜์Šค. 

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฒŒ์‹œ๊ฐ€ ํ•œ ๋ฒˆ์ด๋ผ๋„ ์ด๋ค„์ง„ ๊ฒฝ์šฐ,  android:exported="false"๋กœ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š” ํ•œ, ์ด๋ฆ„ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋ฉด ์•ˆ๋œ๋‹ค.

๊ธฐ๋ณธ๊ฐ’์€ ์—†๋‹ค. ๊ผญ ์ง€์ •ํ•ด์•ผ ํ•œ๋‹ค.

 

android:permission

broadcaster๊ฐ€ broadcast receiver์—๊ฒŒ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ถŒํ•œ ์ด๋ฆ„. 

์ด ์†์„ฑ์ด ์„ค์ •๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฉด <application>์˜ permission์†์„ฑ์„ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค.

์•„๋ฌด ์†์„ฑ๋„ ์„ค์ •๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฉด receiver๊ฐ€ permission์œผ๋กœ ๋ณดํ˜ธ๋˜์ง€ ์•Š๋Š”๋‹ค.

 

android:process

broadcast receiver๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ํ”„๋กœ์„ธ์Šค์˜ ์ด๋ฆ„. ๋ณดํ†ต ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์šฉ์œผ๋กœ ์ƒ์„ฑ๋œ ๊ธฐ๋ณธ ํ”„๋กœ์„ธ์Šค์—์„œ ์‹คํ–‰๋˜๊ณ , ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํŒจํ‚ค์ง€์˜ค ์ด๋ฆ„์ด ๋™์ผํ•˜๋‹ค.