티스토리 뷰

To control who is able to receive the broadcast message, you can use the method sendBroadcast:

public abstract void sendBroadcast (Intent intent, String receiverPermission)

where you precise the name of the required permission. If the receiver does not declare this permission, it will not be able to get the message. For example, the broadcast sender can do:

Intent broadcast = new Intent(this, MyBroadcastReceiver.class);
sendBroadcast(broadcast, "andro.jf.mypermission");

In the manifest of the broadcast sender, a new permission should be declared:

<!--  Declaring the special permission -->
<permission android:name="andro.jf.mypermission" 
        android:label="my_permission" 
        android:protectionLevel="dangerous"></permission>

Then, in the application that is supposed to receive this broadcast, you have to declare this permission and say that you use it. In the manifest you can add:

<!--  I use the permission ! -->
<uses-permission android:name="andro.jf.mypermission"/>

and of course, you have to declare your broadcast receiver:

<receiver android:name="MyBroadcastReceiver" android:exported="true" />

You can have a look at this post for a complete example of a custom permission and also the android developer page about this. Be carefull with the order of installation of your apps because the one that defines the permission should be installed first.

'Android > Android TIP' 카테고리의 다른 글

TextUtils.isEmpty Mockup 만들기 (JUnit)  (0) 2018.04.12
Processing Ordered Broadcasts  (0) 2013.08.21
DP and SP  (0) 2013.07.04
코딩 팁  (0) 2012.10.06
Android TIP  (0) 2012.09.28
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함