2012-03-03 66 views
0

我的接收器不点火,下面的代码:广播接收器不点火

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

尝试还设置动作为IntentI2

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

编辑

。在你的清单一个错字。您的<receiver>标签写为<recevier>。你的应用程序看不到<receiver>

+0

谢谢,但它仍然不起作用 – 2012-03-03 19:07:20

+0

@kenyi我发现你的问题的来源。在你的清单中,正确的单词是'receiver',而不是你写的'recevier',而现在你的应用程序根本看不到接收器。 – Luksprog 2012-03-03 19:23:16

+0

非常感谢!看起来像Eclipse在这个错字中没有检测到错误。 – 2012-03-03 22:49:11