(Android) Broadcast Intent Permissions

本文介绍如何在Android应用中使用权限保护广播,确保广播不会被其他应用程序接收。通过定义权限、设置uses-permission及配置receiver的exported属性,可以实现安全的内部广播通信。此外,还介绍了LocalBroadcastManager的优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

If you want to protect your broadcasts not to be received by other applications directly, one permission is required to define in the AndroidManifest.xml as follows,

 

<permission android:name="test.permission.intent"/>

 

Intent intentA= new Intent("test.intent.a");
sendBroadcast(intentA,"test.permission.intent"/);

 

If you only define this permission and not use this one, your app's receivers also can not receive the intents.

So if want to monitor these intents with permissions, we should add one uses-permission in the AndroidManifestxml.

 

<uses-permission android:name="test.permission.intent"/>

 

 

If you do not want to receive any intent outside of your application, "export = false" in the AndroidManifest.xml is helpful.

<receiver android:name="test.broadcastreceiver"

 android:exported="false">

 ......

< /receiver>

 

 

LocalBroadcastManager

Helper to register for and send broadcasts of Intents to local objects within your process.  This is has a number of advantages over sending global broadcasts with sendBroadcast(Intent)

  • You know that the data you are broadcasting won't leave your app, so don't need to worry about leaking private data. 
  • It is not possible for other applications to send these broadcasts to your app, so you don't need to worry about having security holes they can exploit. 
  • It is more efficient than sending a global broadcast through the system.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值