Sha256: 9a62c7f1d474b69ffa0a0e3d0e281eecb30b42fa0806f46730b8374282097c92

Contents?: true

Size: 1.78 KB

Versions: 15

Compression:

Stored size: 1.78 KB

Contents

package com.moode.sms.plugin;

import android.util.Log;
import com.moode.sms.framework.CommonServiceContext;
import com.moode.sms.service.SMSSendService;
import com.moode.sms.utils.JsonUtils;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Map;

public class MoodeSMS extends Plugin {
    private static final String TAG = MoodeSMS.class.getSimpleName();
    private static final String SEND_SMS_ACTION = "send_sms";
    private static PluginResult OK = new PluginResult(PluginResult.Status.OK);
    private static PluginResult ERROR = new PluginResult(PluginResult.Status.ERROR);

    private static final String MESSAGE_CONTENT_TAG = "message_content";

    @Override
    public PluginResult execute(String action, JSONArray args, String callbackId) {
        Log.d(TAG, "SMS delivery OK");
        Log.d(TAG, action);
        if (action.equalsIgnoreCase(SEND_SMS_ACTION)) {
            return sendMessages(args);
        }

        return ERROR;
    }

    private PluginResult sendMessages(JSONArray jsonArray) {
        try {
            JSONObject receiversObj = (JSONObject) jsonArray.get(0);
            Map<String, String> receivers = JsonUtils.parseReceiversFromJson(receiversObj);
            JSONObject contentObj = (JSONObject) jsonArray.get(1);
            String content = (String) contentObj.get(MESSAGE_CONTENT_TAG);
            getSMSSendService().sendSMS(content, receivers.keySet());
        } catch (JSONException e) {
            Log.e(TAG, "send message error");
            return ERROR;
        }
        return OK;
    }


    private SMSSendService getSMSSendService() {
        return CommonServiceContext.getInstance().getObject(SMSSendService.class);
    }
}

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jt-mobile-kit-1.2.0 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-1.1.8 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-1.1.7 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-1.1.6 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-1.1.5 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-1.1.2 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-1.1.1 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-1.0.3 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-1.0.2 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-1.0.1 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-1.0.0 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-0.0.4 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-0.0.3 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-0.0.2 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java
jt-mobile-kit-0.0.1 lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java