package cordova.plugin.bubbles;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.PluginResult;
import org.json.JSONObject;
import org.json.JSONException;


public class bubbleBroadcastReceiver extends BroadcastReceiver {
    private static final String TAG = "bubbleBroadcastReceiver";
    private CallbackContext callbackContext;
    public static final String ACTION_BARCODE_SERVICE_BROADCAST = "action_barcode_broadcast";
    public static final String KEY_BARCODE_STR = "eventName";    
    
    public bubbleBroadcastReceiver(CallbackContext callbackContext) {
        this.callbackContext = callbackContext;
    }

    public void onReceive(Context ctx, Intent intent) {
            Log.d("bubbleBroadcastReceiver",intent.getExtras().getString(KEY_BARCODE_STR));
            try {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put(KEY_BARCODE_STR, intent.getExtras().getString(KEY_BARCODE_STR));                

                PluginResult result = new PluginResult(PluginResult.Status.OK, jsonObject.toString());
                result.setKeepCallback(true);
                callbackContext.sendPluginResult(result);                
            } catch (JSONException e) {
                e.printStackTrace();
                throw new RuntimeException("JSONException Map Erreur!");
            }
         
    }
    
    
}