2

I'm working on an app that should sent the next alarm time from my phone to my raspberry pi. I managed to get the time of the next alarm, now I need some way to run a bit of code when alarm changed, I've found that changing of the alarm sends a broadcast. My question is, how do I set up a receiver that will only execute code on receiving an alarm change broadcast?

Edit:

package com.dreamdesigns.luke.alarmport;
import android.os.Bundle;
import android.util.Log;
import android.support.v4.content.LocalBroadcastManager;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import android.content.Context;

public class RecieverActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {  

        ...

        // Register to receive messages.
        // We are registering an observer (mMessageReceiver) to receive Intents
        // with actions named "custom-event-name".
        LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
                new IntentFilter("custom-event-name"));
    }

    // Our handler for received Intents. This will be called whenever an Intent
// with an action named "custom-event-name" is broadcasted.
    private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // Get extra data included in the Intent
            String message = intent.getStringExtra("message");
            Log.d("receiver", "Got message: " + message);
        }
    };

    @Override
    protected void onDestroy() {
        // Unregister since the activity is about to be closed.
        LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
        super.onDestroy();
    }

}
user2302718
  • 71
  • 1
  • 10

0 Answers0