package com.deepAround.opensmsapp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class OpenSMSApp extends CordovaPlugin {

	private static final String LOG_TAG = "OpenSMSApp";
	private static volatile Activity currentActivity;
	private SessionCallback callback;

	/**
	 * Initialize cordova plugin kakaotalk
	 * @param cordova
	 * @param webView
	 */
	public void initialize(CordovaInterface cordova, CordovaWebView webView)
	{
		Log.v(LOG_TAG, "OpenSMSApp : initialize");
		super.initialize(cordova, webView);
		currentActivity = this.cordova.getActivity();
	}

	/**
	 * Execute plugin
	 * @param action
	 * @param options
	 * @param callbackContext
	 */
	public boolean execute(final String action, JSONArray options, final CallbackContext callbackContext) throws JSONException
	{
		Log.v(LOG_TAG, "OpenSMSApp : execute " + action);
		cordova.setActivityResultCallback(this);
		callback = new SessionCallback(callbackContext);
		Session.getCurrentSession().addCallback(callback);

		if (action.equals("share")) {

			try {
				this.share(options, callbackContext);
				return true;
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return false;
			}
		}
		return false;
	}
	
	private void share(JSONArray options, final CallbackContext callbackContext){
		try {
			final JSONObject parameters = options.getJSONObject(0);
			
			Intent retunIntent = new Intent(Intent.ACTION_VIEW);
			retunIntent.putExtra("sms_body", parameters.getString("sms_body"));
			retunIntent.setType("vnd.android-dir/mms-sms");
			startActivity(retunIntent);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
@@ -601,49 +601,13 @@
 ty;%0A
-%09private SessionCallback callback;%0A%0A
 %09/**%0A
+
 %09 * 
@@ -1215,112 +1215,8 @@
 is);
-%0A%09%09callback = new SessionCallback(callbackContext);%0A%09%09Session.getCurrentSession().addCallback(callback);
 %0A%0A%09%09
@@ -1784,16 +1784,43 @@
 s%22);%0A%09%09%09
+this.cordova.getActivity().
 startAct
@@ -1896,9 +1896,10 @@
 %0A%09%09%7D%0A%09%7D%0A
-
 %7D
+%0A

Update OpenSMSApp.java