发送自定义广播

2017-06-08  本文已影响0人  yanghanbin_it

发送自定义广播

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void click(View v) {
        //发送自定义广播
        Intent intent = new Intent();
        //自定义action
        intent.setAction("yhbbroadcast1");
        sendBroadcast(intent);
    }
}

接收自定义广播

<receiver
    android:name=".CustomReceiver"
    android:enabled="true"
    android:exported="true" >
    <intent-filter>
        <action android:name="yhbbroadcast1"></action>
    </intent-filter>
</receiver>
上一篇下一篇

猜你喜欢

热点阅读