组件有Public和Private的概念,是否能被其他方调用。通过android:exported字段来确定,android:exported="true"表示能,反之不行。

默认情况下,组件在AndroidMainfest声明中没有 interfliter  那么exported为false,有了interfliter为true.当然我们可以直接输入android:exported来自己控制。以下就设置为false

[html]  view plain copy print ?
  1. <activity  
  2.           android:name=".LoginActivity"  
  3.           android:label="@string/app_name"  
  4.           android:screenOrientation="portrait"   
  5.           android:exported="false">  

我们可以通过自定义permission来限制四大组件的安全

Activity中


在service


在contentprovider中分为写与读的两个权限


在broastreceiver中发送时


接收时


怎么自定义?在androidmainfest中

[html]  view plain copy print ?
  1. <permission android:description="test"    
  2.         android:label="test"    
  3.         android:name="com.test.custempermission"    
  4.         android:protectionLevel="normal">    
  5.     permission>  

下面通过指定一个BroadcastReceiver的权限来实验 
首先创建了两个app,app A ,app B ; 
app A中注册了一个BroadcastReceiver ,app B 发送消息 
app A的menifest文件: 

Xml代码  
  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     package="com.example.testbutton"  
  3.     android:versionCode="1"  
  4.     android:versionName="1.0" >  
  5.   
  6.     <uses-sdk  
  7.         android:minSdkVersion="7"  
  8.         android:targetSdkVersion="15" />  
  9.       
  10.     <permission android:name="com.example.testbutton.RECEIVE" />  
  11.   
  12.     <application  
  13.         android:icon="@drawable/ic_launcher"  
  14.         android:label="@string/app_name"  
  15.         android:theme="@style/AppTheme" >  
  16.         <activity  
  17.             android:name=".MainActivity"  
  18.             launcheMode="singleTask"  
  19.             android:configChanges="locale|orientation|keyboardHidden"  
  20.             android:screenOrientation="portrait"  
  21.             android:theme="@style/android:style/Theme.NoTitleBar.Fullscreen" >  
  22.             <intent-filter>  
  23.                 <action android:name="android.intent.action.MAIN" />  
  24.   
  25.                 <category android:name="android.intent.category.LAUNCHER" />  
  26.             intent-filter>  
  27.         activity>  
  28.           
  29.         <receiver  
  30.             android:name="com.example.testbutton.TestButtonReceiver"  
  31.             android:permission="com.example.testbutton.RECEIVE" >  
  32.             <intent-filter>  
  33.                 <action android:name="com.test.action" />  
  34.             intent-filter>  
  35.         receiver>  
  36.     application>  
  37.   
  38. manifest>  
app B 的menifest 文件内容 
Xml代码  
  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     package="com.example.testsender"  
  3.     android:versionCode="1"  
  4.     android:versionName="1.0" >  
  5.   
  6.     <uses-sdk  
  7.         android:minSdkVersion="7"  
  8.         android:targetSdkVersion="15" />  
  9.       
  10.     <uses-permission android:name="com.example.testbutton.RECEIVE" />  
  11.   
  12.     <application  
  13.         android:icon="@drawable/ic_launcher"  
  14.         android:label="@string/app_name"  
  15.         android:theme="@style/AppTheme" >  
  16.         <activity  
  17.             android:name=".MainActivity"  
  18.             android:label="@string/title_activity_main" >  
  19.             <intent-filter>  
  20.                 <action android:name="android.intent.action.MAIN" />  
  21.   
  22.                 <category android:name="android.intent.category.LAUNCHER" />  
  23.             intent-filter>  
  24.         activity>  
  25.     application>  
  26.   
  27. manifest>  
这样app B 给app A 发送消息,A就可以收到了,若未在app B的menifest文件中声明使用相应的权限,app B发送的消息,A是收不到的。 


更多相关文章

  1. C#开发Android手机应用全接触(mono for android)
  2. Android中TextView文字居中与垂直靠左居中
  3. Android(安卓)界面编程
  4. Android中gravity与layout_gravity的区别, Padding 与 margin 区
  5. Android官方架构组件DataBinding双向绑定篇: 观察者模式的殊途同
  6. Android自定义权限
  7. Android(安卓)UI线程和非UI线程
  8. Android(安卓)系统完整的权限列表
  9. Android之自定义View

随机推荐

  1. 基于 Android(安卓)NDK 的学习之旅-----H
  2. Android(安卓)轻松实现语音识别
  3. 在windows下使用cmd命令通过adb shell自
  4. Android--创建和使用数据库详细指南
  5. 8 个最优秀的 Android(安卓)Studio 插件
  6. OOM问题总结
  7. ESC/POS指令集在Android设备上使用实例(通
  8. 【移动开发】Android中WIFI开发总结(一)
  9. Android(安卓)adb的使用略解
  10. Android多线程:理解和简单使用总结