How to respond once to multiple broadcasts? Jelly Bean LG sending two broadcasts for one event
Tag : java , By : afarouk
Date : March 29 2020, 07:55 AM
wish helps you Just in case anyone comes later w/ the same problem... I couldn't figure out how to deal with multiple broadcasts using boolean values for the state but I did solve this by setting an integer for the state. If the service receives multiple broadcasts for "unplugged" it will always set the int lastHeadsetState to 0. If it receives multiple broadcasts for plugged the first broadcast will set lastHeadsetState to 1 and additional broadcasts will increment lastHeadsetState by 1. I then check if lastHeadsetState equals exactly 1 and then do my work. Any value other than 1 implies multiple broadcasts were received and should be ignored. public class HeadsetService extends Service{
private static final String TAG = "HeadsetService";
private HeadsetReceiver hReceiver;
private int lastHeadsetState;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
hReceiver = new HeadsetReceiver();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Register a new HeadsetReceiver
IntentFilter hfilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
registerReceiver(hReceiver, hfilter);
return START_STICKY;}
private class HeadsetReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
// ignore the initial sticky broadcast when the service starts
if (isInitialStickyBroadcast()) {
}
else {
int state = intent.getIntExtra("state", -1);
switch (state) {
case 0:
Log.d(TAG, "headset unplugged");
//set lastHeadsetState to 0 for later comparison
lastHeadsetState = 0;
Log.d(TAG, "lastHeadsetState set to 0");
break;
case 1:
Log.d(TAG, "headset plugged in!");
lastHeadsetState = (lastHeadsetState + 1);
Log.d(TAG, "lastHeadsetState incremented by 1");
//check if lastHeadsetState is exactly 1...any greater value means multiple broadcasts were received.
if (lastHeadsetState == 1) {
//do whatever you're going to do when the headset is plugged in here
Log.d(TAG, "Headset state has changed from unplugged to plugged");
}
else
Log.d(TAG, "Multiple broadcasts received, ignoring duplicates");
break;
default:
Log.w("uh", "I have no idea what the headset state is");
}
}
}
}
}
}
|
Laravel Echo not receiving Pusher event
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further It was a Namespace issue. Laravel documentation explains it. Event: App\Events\my-event
|
Laravel Echo 500 error not receiving pusher event
Date : March 29 2020, 07:55 AM
I wish this help you This can be caused by an error in your configuration. Here are some things to check: In your .env file, make sure the pusher id, key, and secret are correctly set. If you upgraded from Laravel 5.3 to Laravel 5.4, note that the .env variables PUSHER_KEY is now PUSHER_APP_KEY and PUSHER_SECRET is now PUSHER_APP_SECRET In your config/broadcasting.php, make sure the cluster is set correctly. 'options' => [
'cluster' => 'ap1', // change this to your app's cluster
'encrypted' => false,
],
|
Laravel echo server client not receiving event
Date : March 29 2020, 07:55 AM
hop of those help? The problem is that the client side couldn't connect to the server because the port wasn't responding. Ironically, I just removed the host key from the laravel-echo-server.json config file and re-run the server. Everything worked like a charm!
|
Laravel laravel-echo-server not receiving messages (chat)
Tag : php , By : user186435
Date : March 29 2020, 07:55 AM
seems to work fine First define method on your MessageSent channel named broadcastAs and it return custom name like this: public function broadcastAs()
{
return 'message.sent';
}
window.Echo.private('chat')
.listen('.message.sent', (e) => {
this.messages.push({
body: e.message.body,
user: e.user
});
});
|