Android 四大组件之BroadcastReceiver(发送有序无序广播)

无序广播

发送

/**无序广播*/
				Intent intent =new Intent(Broadcast);
				intent.putExtra("msg", "无序广播已发送");
				sendBroadcast(intent);

接收

public String Broadcast="com.sendbroadcast.action.BROADCAST"; //接收广播适配符(有序无序通用)
if(arg1.getAction().equals(Broadcast)){
			String str=getResultExtras(true).getString("msg");
			Toast.makeText(arg0, str, 1000).show();
			Log.e(">>>>>>>>>>>>>oneBroadcast", str);


注册

 
                //适配符
       



有序广播

发送

/**有序广播*/
Intent intent =new Intent(Broadcast);
intent.putExtra("msg", "无序广播已发送");
sendOrderedBroadcast(intent, "com.sendbroadcast.action.MY_BROADCAST");//权限


接收

if(arg1.getAction().equals(Broadcast)){
			String str=getResultExtras(true).getString("msg");
			Toast.makeText(arg0, str, 1000).show();
			Log.e(">>>>>>>>>>>>>oneBroadcast", str);


更改拦截广播

if(arg1.getAction().equals(Broadcast)){
			String str=arg1.getStringExtra("msg");
			Bundle bundle=new Bundle();
			bundle.putString("msg", str+"广播已更改");
			setResultExtras(bundle);//拦截
			
			Toast.makeText(arg0, str, 1000).show();
			Log.e(">>>>>>>>>>>>>twoBroadcast", str);
		}


注册


      
  
	  

 
       
            
            //有序广播根据优先级大小(-1000到1000)为顺序接收广播
               
               
       






你可能感兴趣的:(Android 四大组件之BroadcastReceiver(发送有序无序广播))