Trigger BroadcastReceiver when I click Button

后端 未结 1 418
遥遥无期
遥遥无期 2021-01-15 23:54

I am trying to recive BroadcastReceiver when i click button on main.xml

                       **mainfest.xml**


        
相关标签:
1条回答
  • 2021-01-16 00:27

    get rid of the pending intent and do it this way:

    on the onclick for your button's click event call:

     public void onClick(View v) {
                // TODO Auto-generated method stub
               broadcastMsg("borad.cast");
    
            }
        });
    

    // and here is the function definition:

    public void broadcastMsg(String intentName) {
            final Intent intent = new Intent(intentName);
            sendBroadcast(intent);
        }
    
    0 讨论(0)
提交回复
热议问题