Reputation: 1884
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
Upvotes: 0
Views: 4428
Reputation: 61
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
Upvotes: 3