How to set permissions in broadcast sender and receiver in android

后端 未结 5 1274
轮回少年
轮回少年 2020-12-04 09:46

How do we specify in broadcast sending application that which application can receive this broadcast, and in receiving application that which particular application has the

5条回答
  •  生来不讨喜
    2020-12-04 10:45

    If you want to restrict who only can send intents to your broadcast receiver, do it this way:

    The broadcast receiver:

    
    
        
        
    
         
            
                
            
        
    
        ...
    
    

    The broadcast sender:

    
        
        
    
        ...
    
    

    Sending broadcast from the sender Activity to the receiver:

    Intent intent = new Intent();
    intent.setAction("my.app.Action");
    activity.sendBroadcast(intent);
    

    If you declare the permission like this:

    
    

    Then the sender will be able to use this permission and send broadcasts to receiver only when both the sender and the receiver apps are signed by the same developer certificate.

提交回复
热议问题