BroadcastReceiver没有开火

时间:2012-03-03 18:51:53

标签: android broadcastreceiver

我的接收器未触发,代码如下:

AndroidManifest

<recevier android:name=".NoticeReceiver" android:enabled="true">
    <intent-filter>
    <action android:name="com.clublifestyle.NoticeService.BROADCAST" />
    </intent-filter>            
</recevier>

NoticeReceiver.java

public class NoticeReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "ASDASD", Toast.LENGTH_SHORT).show();
  }
}

CLMainActivity.java

public class CLMainActivity extends TabActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main);

        this.createTabs();

        Intent i2 = new Intent(this, NoticeReceiver.class);
        this.sendBroadcast(i2);
    }
}
你可以帮我找出原因吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

尝试同时设置Intent i2 的操作:

Intent i2 = new Intent();
i2.setAction("com.clublifestyle.NoticeService.BROADCAST");
this.sendBroadcast(i2);

修改

你的清单中有一个拼写错误。您将<receiver>标记写为<recevier>。您的应用看不到<receiver>