Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating Activity from separate broadcastreceiver, how?
    primarykey
    data
    text
    <p>I am writing an application which catches media-button-clicks from a bt-headset. However, since my receiver is stated in the manifest-file, I am suddenly not in control of my activity any more, and what I really want to do is to "press" a software-button on the activity when somebody presses the headset button.</p> <p>I've tried several solutions but have not got anything to work. Here is my current state</p> <pre><code>package com.siriforreq.activities; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class MediaButtonReceiver extends BroadcastReceiver{ private boolean gotMessage = false; public MediaButtonReceiver(){ super(); } public boolean isMessage(){ return this.gotMessage; } @Override public void onReceive(Context context, Intent intent) { System.out.println("IN ON RECEIVE1"); if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) { System.out.println("GOT MEDIA BUTTON"); Intent startBroadcastIntent = new Intent(context, NetworkActivity.class); startBroadcastIntent.setAction("com.siriforerq.activities.ACTION_LOL"); startBroadcastIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); System.out.println("...sending broadcast"); context.sendBroadcast(startBroadcastIntent); } } } </code></pre> <p>In the above receiver, I do catch the media button. But where do I go from now to update my Activity? What I am trying to do right now is to send another custom broadcast and catch that in another receiver within the activity, but it does not seem to work. Here is my Activity: </p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_network); mMediaReceiverCompName = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName()); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); IntentFilter btCommunicationFilter = new IntentFilter(); btCommunicationFilter.setPriority(1000); btCommunicationFilter.addAction("com.siriforerq.activities.ACTION_LOL"); catchButtonEvent = new BroadcastReceiver(){ @Override public void onReceive(Context context, Intent intent) { System.out.println("Got broadcast yes"); //startTalkInteraction(); &lt;- this is the method I want to call in the activity } }; registerReceiver(catchButtonEvent, btCommunicationFilter); } public void onResume() { super.onResume(); mAudioManager.registerMediaButtonEventReceiver(mMediaReceiverCompName); socketNetworkHelper = SocketNetworkHelper.getSocketNetworkHelper(ip, port); setButtonStatus(true); } </code></pre> <p>In the above anonymous receiver, the broadcast that is being sent from the MediaButtonReceiver never gets called and here is my problem right now. Should I think in another way or why doesn't my onReceive in the anonymous receiver-class trigger?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload