Android广播接收器和意图过滤器

时间:2011-12-11 04:09:22

标签: android broadcastreceiver intentfilter

我是android平台新手。请帮助我了解广播接收器和Intent Filter在android中的行为。
除了

之外还有其他方式进行广播
public class OutGoingBrodcast extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            System.err.println("OUTGOING");
            Intent i=new Intent();
            i.setAction("com.ith.OUT");
            context.sendBroadcast(i);

        }

    }

接收广播

    public class IncomingBroadcast extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            if(intent.getAction().equals("com.ith.OUT")){
                System.out.println("hit INCOMING");
            }
        }

    }

mainfest

<receiver android:name=".OutgoingReceiver" android:enabled="true">
    <intent-filter>
        <action android:name="android.intent.action.SCREEN_OFF"></action>
    </intent-filter>
</receiver>
<receiver android:name=".IncomingReceiver" android:enabled="true">
    <intent-filter>
        <action android:name="com.ith.OUT"></action>
    </intent-filter>
</receiver>

我想知道除了

之外还有其他任何方式进行广播
Intent i=new Intent();
i.setAction("com.ith.OUT");
context.sendBroadcast(i);

使用com.ith.OUT

等自定义意图过滤器

0 个答案:

没有答案