android BroadCasetReceiver讲解

来源:互联网 发布:剑灵御姐灵女捏脸数据 编辑:程序博客网 时间:2024/04/27 16:55

简介:

BroadcastReceiver: 广播接收器,一个专门接收广播的东东,它需要在系统中进行注册,注册方式有静态注册(在manifest.xml中注册)和动态注册(在Activity或service中注册)两种, 注册的作用就是告诉系统,我只接收什么样的广播(具体通过action属性设置),如果有这样的广播,就叫我一声,我来处理下。


静态注册:在manifest.xml中进行注册,表示只要是Android.intent.action.mybroadcast_action这个地址的广播,MyBroadcastReceiverS1都能够接收的到。注意,这种方式的注册是常驻型的,也就是说当应用关闭后,如果有广播信息传来,MyBroadcastReceiverS1也会被系统调用而自动运行。

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <!-- 在manifest。xml中注册广播接收者 -->  
  2.         <receiver android:name="com.androidstudydemo.broadcastReceiver.MyBroadcastReceiverS1" >  
  3.             <intent-filter android:priority="1000" >  
  4.                 <action android:name="android.intent.action.mybroadcast_action" />  
  5.                 <category android:name="android.intent.category.DEFAULT" />  
  6.             </intent-filter>  
  7.         </receiver>  


动态注册:在代码中动态的指定广播地址并注册,通常我们是在Activity或Service注册一个广播,这种注册方式与静态注册相反,不是常驻型的,也就是说广播会跟随程序的生命周期,当Activity或service销毁时,我们必须对Receiver解除注册,否则会报异常,因此我们要在特定的方法中对Receiver进行解除注册。

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. //在Activity中动态的注册广播接收器  
  2. battertChangeReceiver = new MyBroadcastReceiverD4();  
  3.         IntentFilter filter = new IntentFilter(  
  4.                 "android.intent.action.MY_BROADCAST");  
  5.         registerReceiver(battertChangeReceiver, filter);  
  6.       
  7. //在Activity的destroy方法解除注册  
  8. @Override  
  9. protected void onDestroy() {  
  10.     super.onDestroy();  
  11.     unregisterReceiver(battertChangeReceiver);  
  12. }  

如果有多个接收者都注册了相同的广播地址,又会是什么情况呢,能同时接收到同一条广播吗,相互之间会不会有干扰呢?这就涉及到普通广播和有序广播的概念了。

普通广播:对于多个接收者来说是完全异步的,通常每个接收者都无需等待即可以接收到广播,接收者相互之间不会有影响。对于这种广播,接收者无法终止广播,即无法阻止其他接收者的接收动作。

有序广播:有序广播比较特殊,它每次只发送到优先级较高的接收者那里,然后由优先级高的接受者再传播到优先级低的接收者那里,优先级高的接收者有能力终止这个广播。静态注册的有序广播要加上android:priority="1000"属性来定义优先级,动态的可以在代码中设置setPriority();发送有序广播调用方法sendOrderedBroadcast(Intent intent,String permission);

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <!-- 在manifest。xml中注册广播接收者,有序广播需要指定priority属性,同时注意,一个接收器可以注册多种类型的广播,如下面定义的MyBroadcastReceiverS3 -->  
  2.         <receiver android:name="com.androidstudydemo.broadcastReceiver.MyBroadcastReceiverS1" >  
  3.             <intent-filter android:priority="1000" >  
  4.                 <action android:name="android.intent.action.mybroadcast_action" />  
  5.   
  6.                 <category android:name="android.intent.category.DEFAULT" />  
  7.             </intent-filter>  
  8.         </receiver>  
  9.         <receiver android:name="com.androidstudydemo.broadcastReceiver.MyBroadcastReceiverS2" >  
  10.             <intent-filter android:priority="999" >  
  11.                 <action android:name="android.intent.action.mybroadcast_action" />  
  12.   
  13.                 <category android:name="android.intent.category.DEFAULT" />  
  14.             </intent-filter>  
  15.         </receiver>  
  16.         <!--定义两个action,该Receiver可以接收多种类型的广播 -->  
  17.         <receiver android:name="com.androidstudydemo.broadcastReceiver.MyBroadcastReceiverS3" >  
  18.             <intent-filter android:priority="998" >  
  19.                 <action android:name="android.intent.action.mybroadcast_action" />  
  20.                 <action android:name="android.net.conn.CONNECTIVITY_CHANGE"></action>  
  21.                 <category android:name="android.intent.category.DEFAULT" />  
  22.             </intent-filter>  
  23.         </receiver>  

在发送的有序广播的前提下,在广播的Receiver方法里面调用setResultExtras(bundle),那么优先接收到Broadcast的接收者可以通过setResultExtras(Bundle)方法将处理结果存入Broadcast中,然后传给下一个接收者,非有序广播即使设置了也无效。
[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. //如果是发送的有序广播,那么优先接收到Broadcast的接收者可以通过setResultExtras(Bundle)方法将处理结果存入Broadcast中,然后传给下一个接收者  
  2.         Bundle bundle = new Bundle();  
  3.         bundle.putString("msg", msg + "@MyBroadcastReceiverS2");  
  4.         setResultExtras(bundle);  

调用abortBroadcast()可以停止广播的传播,此方法只对有序广播有效,普通广播无效。高优先级的Receiver调用该方法之后,低优先级的Receiver将不会接收到广播。

使用sendOrderedBroadcast方法发送有序广播时,需要一个权限参数,如果为null则表示不要求接收者声明指定的权限,如果不为null,则表示接收者若要接收此广播,需声明指定权限。这样做是从安全角度考虑的,例如系统的短信就是有序广播的形式,一个应用可能是具有拦截垃圾短信的功能,当短信到来时它可以先接受到短信广播,必要时终止广播传递,这样的软件就必须声明接收短信的权限。

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. case R.id.button2:// 有序广播  
  2. intent = new Intent("android.intent.action.mybroadcast_action");  
  3. intent.putExtra("type"2);  
  4. intent.putExtra("msg""发送有序广播 ");  
  5. //发送有序广播  
  6. sendOrderedBroadcast(intent,"scott.permission.mybroadcast_permission");  
  7. break;  


所以我们在AndroidMainfest.xml中定义一个权限(关于权限定义,声明与使用,请参照:http://blog.csdn.NET/liuhe688/article/details/6417983),然后使用该权限:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <!-- 自定义权限 -->  
  2.    <permission  
  3.        android:name="scott.permission.mybroadcast_permission"  
  4.        android:protectionLevel="normal" >  
  5.    </permission>  
  6.   
  7.    <!-- 使用自定义的权限 -->  
  8.    <uses-permission android:name="scott.permission.mybroadcast_permission" />   


以下是我做的project,实现静态注册,动态注册等功能。

1. 静态注册的MyBroadcastReceiverS1

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. package com.androidstudydemo.broadcastReceiver;  
  2.   
  3. import com.androidstudydemo.common.util.DisPlayUtil;  
  4.   
  5. import android.content.BroadcastReceiver;  
  6. import android.content.Context;  
  7. import android.content.Intent;  
  8. import android.os.Bundle;  
  9. import android.os.Handler;  
  10. import android.os.Message;  
  11. import android.sax.StartElementListener;  
  12. import android.util.Log;  
  13. import android.widget.TextView;  
  14.   
  15. /** 
  16.  * broadcastreceiver注册有两种方法,一种静态注册,一种动态注册,此对象采用静态注册,即 在manifest.xml文件中进行注册。 
  17.  *  
  18.  * @author zkx016 
  19.  *  
  20.  */  
  21. public class MyBroadcastReceiverS1 extends BroadcastReceiver {  
  22.   
  23.     String TAG = "MyBroadcastReceiverS1";  
  24.   
  25.     @Override  
  26.     public void onReceive(Context arg0, Intent arg1) {  
  27.         int type = arg1.getIntExtra("type"1);  
  28.         String msg = arg1.getStringExtra("msg");  
  29.         msg += getResultExtras(true).getString("msg");  
  30.   
  31.         Log.i(TAG, "MyBroadcastReceiverS1:" + type + "/" + msg);  
  32.   
  33.         String info = TAG + "==>  action is:" + arg1.getAction()  
  34.                 + "  message is:" + msg;  
  35.         DisPlayUtil.ShowToastMessage(arg0, info);  
  36.   
  37.         Handler handler = MyBroadcastSenderActivity.getHandler();// 将信息发送给activity更新textView  
  38.         Message message = handler.obtainMessage();  
  39.         message.what = 1;  
  40.         message.obj = info;  
  41.         message.sendToTarget();  
  42.   
  43.         // 如果是发送的有序广播,那么优先接收到Broadcast的接收者可以通过setResultExtras(Bundle)方法将处理结果存入Broadcast中,然后传给下一个接收者,若是普通广播,下面的请直接忽略  
  44.         Bundle bundle = new Bundle();  
  45.         bundle.putString("msg", msg + "@MyBroadcastReceiverS1");  
  46.         setResultExtras(bundle);  
  47.     }  
  48.   
  49. }  

2.静态注册的MyBroadcastReceiverS2.java

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. package com.androidstudydemo.broadcastReceiver;  
  2.   
  3. import com.androidstudydemo.common.util.DisPlayUtil;  
  4.   
  5. import android.content.BroadcastReceiver;  
  6. import android.content.Context;  
  7. import android.content.Intent;  
  8. import android.os.Bundle;  
  9. import android.os.Handler;  
  10. import android.os.Message;  
  11. import android.util.Log;  
  12. import android.widget.TextView;  
  13.   
  14. public class MyBroadcastReceiverS2 extends BroadcastReceiver {  
  15.   
  16.     String TAG = "MyBroadcastReceiverS2";  
  17.   
  18.     @Override  
  19.     public void onReceive(Context arg0, Intent arg1) {  
  20.         int type = arg1.getIntExtra("type"1);  
  21.         String msg = arg1.getStringExtra("msg");  
  22.         Bundle bundle1 = getResultExtras(true);  
  23.         msg += bundle1.getString("msg");  
  24.   
  25.         Log.i(TAG, msg);  
  26.   
  27.         String info = TAG + "==>  action is:" + arg1.getAction()  
  28.                 + "  message is:" + msg;  
  29.         DisPlayUtil.ShowToastMessage(arg0, info);  
  30.   
  31.         Handler handler = MyBroadcastSenderActivity.getHandler();// 将信息发送给activity更新textView  
  32.         Message message = handler.obtainMessage();  
  33.         message.what = 1;  
  34.         message.obj = info;  
  35.         message.sendToTarget();  
  36.   
  37.         // 如果是发送的有序广播,那么优先接收到Broadcast的接收者可以通过setResultExtras(Bundle)方法将处理结果存入Broadcast中,然后传给下一个接收者  
  38.         Bundle bundle = new Bundle();  
  39.         bundle.putString("msg", msg + "@MyBroadcastReceiverS2");  
  40.         setResultExtras(bundle);  
  41.         abortBroadcast();//终止广播的继续传播,可以看见,broadCastReceiverS3没有接收到广播  
  42.   
  43.     }  
  44.   
  45. }  


3.静态注册的MyBroadcastReceiverS3 

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. package com.androidstudydemo.broadcastReceiver;  
  2.   
  3. import com.androidstudydemo.common.util.DisPlayUtil;  
  4.   
  5. import android.content.BroadcastReceiver;  
  6. import android.content.Context;  
  7. import android.content.Intent;  
  8. import android.net.ConnectivityManager;  
  9. import android.net.NetworkInfo;  
  10. import android.os.Bundle;  
  11. import android.os.Handler;  
  12. import android.os.Message;  
  13. import android.util.Log;  
  14. import android.widget.TextView;  
  15. import android.widget.Toast;  
  16.   
  17. public class MyBroadcastReceiverS3 extends BroadcastReceiver {  
  18.   
  19.     String TAG = "MyBroadcastReceiverS3";  
  20.   
  21.     @Override  
  22.     public void onReceive(Context arg0, Intent arg1) {  
  23.         int type = arg1.getIntExtra("type"1);  
  24.         String msg = arg1.getStringExtra("msg");  
  25.         msg += getResultExtras(true).getString("msg");  
  26.         Log.i(TAG, msg);  
  27.   
  28.         String info = TAG + "==>  action is:" + arg1.getAction()  
  29.                 + "  message is:" + msg;  
  30.         DisPlayUtil.ShowToastMessage(arg0, info);  
  31.   
  32.         Handler handler = MyBroadcastSenderActivity.getHandler();// 将信息发送给activity更新textView  
  33.         Message message = handler.obtainMessage();  
  34.         message.what = 1;  
  35.         message.obj = info;  
  36.         message.sendToTarget();  
  37.   
  38.         // 如果是发送的有序广播,那么优先接收到Broadcast的接收者可以通过setResultExtras(Bundle)方法将处理结果存入Broadcast中,然后传给下一个接收者  
  39.         Bundle bundle = new Bundle();  
  40.         bundle.putString("msg", msg + "@MyBroadcastReceiverS3");  
  41.         setResultExtras(bundle);  
  42.   
  43.         //当网络可用发生变化时,系统会发出一个广播,所以我们在断开网络或重启网络时不用我们自己手动的发一个广播。  
  44.         if (!isNetworkAvailable(arg0)) {    
  45.             Toast.makeText(arg0, "network disconnected!"0).show();    
  46.         }    
  47.     }  
  48.       
  49.      /**  
  50.      * 网络是否可用  
  51.      *   
  52.      * @param context  
  53.      * @return  
  54.      */    
  55.     public static boolean isNetworkAvailable(Context context) {    
  56.         ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);    
  57.         NetworkInfo[] info = mgr.getAllNetworkInfo();    
  58.         if (info != null) {    
  59.             for (int i = 0; i < info.length; i++) {    
  60.                 if (info[i].getState() == NetworkInfo.State.CONNECTED) {    
  61.                     return true;    
  62.                 }    
  63.             }    
  64.         }    
  65.         return false;    
  66.     }    
  67.   
  68. }  

4.动态注册的MyBroadcastReceiverD4.java,在BatteryChangeActivity中动态注册,一进入页面即提示当前电量。

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. package com.androidstudydemo.broadcastReceiver;  
  2.   
  3. import android.content.BroadcastReceiver;  
  4. import android.content.Context;  
  5. import android.content.Intent;  
  6. import android.os.BatteryManager;  
  7. import android.util.Log;  
  8. import android.widget.Toast;  
  9.   
  10. public class MyBroadcastReceiverD4 extends BroadcastReceiver {  
  11.   
  12.     String TAG = "MyBroadcastReceiverD4";  
  13.   
  14.     @Override  
  15.     public void onReceive(Context arg0, Intent intent) {  
  16.   
  17.         int currLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); // 当前电量  
  18.         int total = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 1); // 总电量  
  19.         int percent = currLevel * 100 / total;  
  20.         Toast.makeText(arg0, "当前电量:" + percent, 0).show();  
  21.   
  22.         Log.i(TAG, "battery: " + percent + "%");  
  23.     }  
  24.   
  25. }  


5.主界面MyBroadcastSenderActivity,里面包含三个按钮:发送普通广播,发送有序广播,动态注册示例 三个按钮。

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. package com.androidstudydemo.broadcastReceiver;  
  2.   
  3. import java.util.HashMap;  
  4.   
  5. import android.content.Intent;  
  6. import android.content.IntentFilter;  
  7. import android.os.Bundle;  
  8. import android.os.Handler;  
  9. import android.view.View;  
  10. import android.view.View.OnClickListener;  
  11. import android.widget.Button;  
  12. import android.widget.TextView;  
  13.   
  14. import com.androidstudydemo.common.BaseActivity;  
  15. import com.androidstudydemo.common.MyTitleView;  
  16. import com.androidstudydemo.common.R;  
  17. import com.androidstudydemo.common.util.DisPlayUtil;  
  18.   
  19. public class MyBroadcastSenderActivity extends BaseActivity implements  
  20.         OnClickListener {  
  21.   
  22.     static TextView textView = null;  
  23.     MyTitleView title = null;  
  24.     // MyBroadcastReceiver1 receiver1; receiver1通过在manifest。xml中进行注册  
  25.     MyBroadcastReceiverS2 receiver2;// 在代码中动态注册。  
  26.     int i = 1;  
  27.   
  28.     static Handler handler = new Handler() {  
  29.         public void handleMessage(android.os.Message msg) {  
  30.             switch (msg.what) {  
  31.             case 1:  
  32.                 if (textView != null) {  
  33.                     String info = (String) msg.obj;  
  34.                     textView.append(info);  
  35.                 }  
  36.                 break;  
  37.   
  38.             default:  
  39.                 break;  
  40.             }  
  41.         };  
  42.     };  
  43.   
  44.     public static Handler getHandler() {  
  45.         return handler;  
  46.     }  
  47.   
  48.     @Override  
  49.     protected void onStart() {  
  50.         super.onStart();  
  51.         // 静态注册,一般是在onstart方法进行注册,在onstop方法进行销毁  
  52.         receiver2 = new MyBroadcastReceiverS2();  
  53.         IntentFilter filter2 = new IntentFilter();  
  54.         filter2.addAction("myaction");  
  55.         registerReceiver(receiver2, filter2);  
  56.     }  
  57.   
  58.     @Override  
  59.     protected void onStop() {  
  60.         super.onStop();  
  61.         if (receiver2 != null) {// 动态注册,在activity销毁时要解除注册,否则会报错。  
  62.             unregisterReceiver(receiver2);  
  63.         }  
  64.     }  
  65.   
  66.     public void initTitle(MyTitleView title) {  
  67.         HashMap<String, Object> datas = new HashMap<String, Object>();  
  68.         datas.put("title", R.string.broadcastReceiver_title);  
  69.         datas.put("instration", R.string.broadcastReceiver_isntration);  
  70.         title.setInitDatas(datas);  
  71.     }  
  72.   
  73.     @Override  
  74.     protected void onCreate(Bundle savedInstanceState) {  
  75.   
  76.         super.onCreate(savedInstanceState);  
  77.         setContentView(R.layout.activity_mybroadcastsenderdemo);  
  78.         textView = (TextView) this.findViewById(R.id.textView1);  
  79.         title = (MyTitleView) this.findViewById(R.id.title);  
  80.         initTitle(title);  
  81.     }  
  82.   
  83.     public void initInstration() {  
  84.         HashMap<String, String> map = new HashMap<String, String>();  
  85.         map.put("title""broadcastReceiver讲解");  
  86.         map.put("message",  
  87.                 getResources().getString(R.string.broadcastReceiver_isntration));  
  88.         DisPlayUtil.showAlertDialog(MyBroadcastSenderActivity.this, map);  
  89.     }  
  90.   
  91.     @Override  
  92.     public void onClick(View arg0) {  
  93.         Intent intent;  
  94.         switch (arg0.getId()) {  
  95.         case R.id.button1:// 普通广播  
  96.             intent = new Intent("android.intent.action.mybroadcast_action");  
  97.             intent.putExtra("type"1);  
  98.             intent.putExtra("msg""发送普通广播 ");  
  99.             sendBroadcast(intent);  
  100.             break;  
  101.         case R.id.button2:// 有序广播  
  102.             intent = new Intent("android.intent.action.mybroadcast_action");  
  103.             intent.putExtra("type"2);  
  104.             intent.putExtra("msg""发送有序广播 ");  
  105.             sendOrderedBroadcast(intent,"scott.permission.mybroadcast_permission");  
  106.             break;  
  107.         case R.id.button3:  
  108.             intent = new Intent(this, BatteryChangeActivity.class);  
  109.             startActivity(intent);  
  110.             break;  
  111.         case R.id.button4:  
  112.             break;  
  113.         default:  
  114.             break;  
  115.         }  
  116.   
  117.     }  
  118. }  



6.用于动态注册的BatteryChangeActivity
[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. package com.androidstudydemo.broadcastReceiver;  
  2.   
  3. import android.content.Intent;  
  4. import android.content.IntentFilter;  
  5. import android.os.Bundle;  
  6.   
  7. import com.androidstudydemo.common.BaseActivity;  
  8.   
  9. public class BatteryChangeActivity extends BaseActivity {  
  10.   
  11.     MyBroadcastReceiverD4 battertChangeReceiver;  
  12.   
  13.     @Override  
  14.     protected void onCreate(Bundle savedInstanceState) {  
  15.         // TODO Auto-generated method stub  
  16.         super.onCreate(savedInstanceState);  
  17.   
  18.         battertChangeReceiver = new MyBroadcastReceiverD4();  
  19.         IntentFilter filter = new IntentFilter(  
  20.                 "android.intent.action.MY_BROADCAST");  
  21.         registerReceiver(battertChangeReceiver, filter);  
  22.           
  23.         Intent batteryIntent = new Intent("android.intent.action.MY_BROADCAST");    
  24.         sendBroadcast(batteryIntent);  
  25.     }  
  26.   
  27.     @Override  
  28.     protected void onDestroy() {  
  29.         // TODO Auto-generated method stub  
  30.         super.onDestroy();  
  31.         unregisterReceiver(battertChangeReceiver);  
  32.     }  
  33. }  


7. 静态注册和权限配置manifest.xml

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <!-- android:installLocation="auto" 自动选择安装位置(sd卡或手机内存) -->  
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     package="com.androidstudydemo.common"  
  5.     android:installLocation="auto"  
  6.     android:versionCode="1"  
  7.     android:versionName="1.0" >  
  8.   
  9.     <uses-sdk  
  10.         android:minSdkVersion="8"  
  11.         android:targetSdkVersion="16" />  
  12.   
  13.     <!-- 自定义权限 -->  
  14.     <permission  
  15.         android:name="scott.permission.mybroadcast_permission"  
  16.         android:protectionLevel="normal" >  
  17.     </permission>  
  18.      
  19.     <!-- 使用自定义的权限 -->  
  20.     <uses-permission android:name="scott.permission.mybroadcast_permission" />    
  21.          
  22.     <!-- 使用网络功能所需权限 -->  
  23.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >  
  24.     </uses-permission>  
  25.     <uses-permission android:name="android.permission.INTERNET" >  
  26.     </uses-permission>  
  27.          
  28.     <application  
  29.         android:allowBackup="true"  
  30.         android:icon="@drawable/ic_launcher"  
  31.         android:label="@string/app_name"  
  32.         android:theme="@style/AppTheme" >  
  33.         <uses-library android:name="android.test.runner" />  
  34.          
  35.         <!-- 在manifest.xml中注册广播接收者 -->  
  36.         <receiver android:name="com.androidstudydemo.broadcastReceiver.MyBroadcastReceiverS1" >  
  37.             <intent-filter android:priority="1000" >  
  38.                 <action android:name="android.intent.action.mybroadcast_action" />  
  39.   
  40.                 <category android:name="android.intent.category.DEFAULT" />  
  41.             </intent-filter>  
  42.         </receiver>  
  43.         <receiver android:name="com.androidstudydemo.broadcastReceiver.MyBroadcastReceiverS2" >  
  44.             <intent-filter android:priority="999" >  
  45.                 <action android:name="android.intent.action.mybroadcast_action" />  
  46.   
  47.                 <category android:name="android.intent.category.DEFAULT" />  
  48.             </intent-filter>  
  49.         </receiver>  
  50.         <receiver android:name="com.androidstudydemo.broadcastReceiver.MyBroadcastReceiverS3" >  
  51.             <intent-filter android:priority="998" >  
  52.                 <action android:name="android.intent.action.mybroadcast_action" />  
  53.         <action android:name="android.net.conn.CONNECTIVITY_CHANGE"></action>  
  54.                 <category android:name="android.intent.category.DEFAULT" />  
  55.             </intent-filter>  
  56.         </receiver>  
  57.           
  58.         <activity  
  59.             android:name="com.androidstudydemo.main.MainActivity"  
  60.             android:label="@string/app_name" >  
  61.             <intent-filter>  
  62.                 <action android:name="android.intent.action.MAIN" />  
  63.   
  64.                 <category android:name="android.intent.category.LAUNCHER" />  
  65.             </intent-filter>  
  66.         </activity>  
  67.         <activity  
  68.             android:name="com.androidstudydemo.broadcastReceiver.MyBroadcastSenderActivity"  
  69.             android:label="@string/app_name" >  
  70.         </activity>  
  71.          <activity  
  72.             android:name="com.androidstudydemo.broadcastReceiver.BatteryChangeActivity"  
  73.             android:label="@string/app_name" >  
  74.         </activity>  
  75.           
  76.     </application>  
  77. </manifest>  

0 0
原创粉丝点击