简体   繁体   中英

TIME_TICK action not calling broadcast receiver

I have written a simple broadcast receiver responding to TIME_TICK action .

When I add the action in the manifest file it is not calling the registered receiver but when I register the receiver in the java code it is being called. I have a simple onreceive method.

public class mybroad extends BroadcastReceiver
{
    @Override
    public void onReceive(Context arg0, Intent arg1) {
        // TODO Auto-generated method stub
        Log.v("got", "broadcasted");
        Toast.makeText(arg0, "hurray broadcast got", Toast.LENGTH_LONG).show();


    }

}

receiver tag for manifest file

<receiver android:name="com.example.chapbasic.mybroad" >
            <intent-filter>
                <action android:name="android.intent.action.TIME_TICK"></action>
            </intent-filter>
        </receiver>

when I operate with the following code it is working

public class broadact extends Activity
{
    IntentFilter ii;
    mybroad mb;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mybroad);
    ii=new IntentFilter("android.intent.action.TIME_TICK");
    mb=new mybroad();

}
@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    registerReceiver(mb, ii);
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    unregisterReceiver(mb);
}

Kindly update why it is not being called from the manifest file registration. thanks

kindly go through the documentation that states.

You can not receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver() .

That is why you are not able to receive it when doing through manifest file. thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM