Android broadcast receiver not working

前端 未结 4 851
庸人自扰
庸人自扰 2020-12-16 00:55

I try to get a broadcast receiver working. Should be as simple as possible, I have my manifest like this:


&l         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 01:52

    Please setClass for your Intent,

    EX:

    public class mainAct extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Intent i=new Intent("any string");
            i.setClass(this, MyIntentRec.class);
            this.sendBroadcast(i);
        }
    }
    

    That is what it means " The absence of any filters means that it can be invoked only by Intent objects that specify its exact class name."

    [Old answer]
    You should register what kind of actions you need in the manifest.
    Ex:

        
            
                
            
        
    

    send it,

    this.sendBroadcast(new Intent("your.intent"));
    

提交回复
热议问题