How to do custom broadcasts in Android can only be received by the specified app

Source: Internet
Author: User

Today no hanging things, and went to the interview, the specific company will not say, because I noted in the previous blog the names of those companies, the result people gave me a private messages said I leaked their title, OK, I was wrong ... In fact, when we are already at work, we can go to the side in the free time, because the interview has many advantages:

1th: You know the specific address of the company, and later talk with friends also have a topic

2nd: This is very important, look at the other company's face test (now some companies are still using the pen test this link, really no words, the topic is all from the Internet to find, very no meaning, so I just see a pen test all pass, personal feeling face to now, Ali and drip is still good, They will ask you the specific questions they encounter in the project, ask you how to solve them, this answer is not sure, test you are experience)


The above said a lot, the following to get to the point:

Title: How to do a custom broadcast in Android can only be received by the specified app

Idea: In fact, the first time I thought of the answer should be to add access to the broadcast, but I have been to the activity's access to add permissions, so here is not sure right, but I feel that the four components of Android should be the same. Rub, the result was I was blindfolded. haha ~ ~


We use the API form in Android, or we can use the ADB command to open an app's activity/service externally and send a broadcast. So this is not safe for an application. That is, permissions are a protection mechanism.


Solution Ideas:

In fact, there is no technology to say, is the Android can be customized permissions, for the four components of Access plus a layer of protection, not much to say, directly on the code:


Send broadcast:

Package Com.tt.test;import Android.app.activity;import Android.content.componentname;import android.content.Intent Import Android.os.bundle;import Android.view.view;import Android.widget.button;public class Main extends Activity {    @Override public    void OnCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.main);        (Button) Findviewbyid (R.id.button)). Setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick ( View v) {   Intent i = new Intent ("COM. MESSAGE ");   I.addcategory ("receiver");   I.putextra ("message", "haha");   Sendorderedbroadcast (i, "xvtian.gai.receiver");}});}}    
Androidmanifest.xml:

<uses-permission android:name= "Xvtian.gai.receiver" ></uses-permission>  <permission android: Protectionlevel= "Normal" android:name= "Xvtian.gai.receiver" ></permission>

Receive broadcast:

Package Com.tt.receiver;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;import Android.util.log;public class Receiver extends Broadcastreceiver {@Overridepublic void OnReceive (context context, Intent Intent) {log.d ("TAG", "Receiver Intent:" + intent.tostring ());}}
Androidmanifest.xml

<uses-permission android:name= "Xvtian.gai.receiver" ></uses-permission>
<receiver android:name= ". Receiver "android:permission=" xvtian.gai.receivers ">       <intent-filter>         <action android:name=" Com. MESSAGE "/>         <category android:name=" receiver "/>       </intent-filter></receiver>


Simple, no technology to say, the same way we can do other components of the rights protection (may use more of the activity access to add permissions), of course, I generally develop the application does not seem to use these things, but if you want to learn, should go to those who do security applications, For example, 360 mobile defender, after the anti-compilation open his Androidmanifest.xml file, you will be shocked, at the same time you can learn a lot. haha ~ ~


Demo:

http://download.csdn.net/detail/jiangwei0910410003/7973867



How to make a custom broadcast in Android can only be received by the specified app

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.