How to pass data to BroadcastReceiver?

后端 未结 5 999
难免孤独
难免孤独 2020-12-08 21:43

What I am trying to do is that the numbers to which my application sends messages to, are passed to the BraodcastReceiver...but so far either I am getting null or BroadcastR

5条回答
  •  盖世英雄少女心
    2020-12-08 21:58

    You starting an Activity instead of broadcasting Intent. Try to change

    startActivity(intent);
    

    to

    sendBroadcast(intent);
    

    UPDATE:

    You set no action and no component name to the Intent. Try create intent as following:

    Intent intent = new Intent(context, YourReceiver.class);
    intent.putExtra("phN", phoneNo);
    sendBroadcast(intent);
    

提交回复
热议问题