package com.telepin.cellTower;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaInterface;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;

import android.content.Context;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;

import android.provider.Settings;

public class LocationInfo extends CordovaPlugin {

	public static final String ACTION = "getCID";

	 /**
     * Constructor.
     */
    public LocationInfo() {
    }
    
    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);
    }
    
	@Override
	public boolean execute(String action, JSONArray data,
			CallbackContext callbackContext) throws JSONException {

		try {
			if (action.equals(ACTION)) {
				
				JSONObject r = new JSONObject();
				r.put("cid", this.getCellID());
				callbackContext.success(r);
				return true;
			}
			callbackContext.error("Invalid action");
			return false;
		} catch (Exception e) {
			System.err.println("Exception: " + e.getMessage());
			callbackContext.error(e.getMessage());
			return false;
		}
	}

	public int getCellID() throws IOException {
		TelephonyManager tm = (TelephonyManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
		GsmCellLocation location = (GsmCellLocation) tm.getCellLocation();
		int cellID = location.getCid();
		Log.i("Cell ID", cellID+"");
		return cellID;
	}

}

@@ -596,17 +596,13 @@
 ;%0A%0A%09
- 
 /**%0A
-    
+%09
  * C
@@ -617,20 +617,14 @@
 or.%0A
-     */%0A    
+%09 */%0A%09
 publ
@@ -647,23 +647,24 @@
 ) %7B%0A
-    %7D%0A    %0A    
+%09%7D%0A%0A%09@Override%0A%09
 publ
@@ -738,16 +738,10 @@
 ) %7B%0A
-        
+%09%09
 supe
@@ -776,18 +776,11 @@
 w);%0A
-    %7D%0A    
+%09%7D%0A
 %0A%09@O
@@ -906,17 +906,8 @@
  %7B%0A%0A
-%09%09try %7B%0A%09
 %09%09if
@@ -937,90 +937,24 @@
 ) %7B%0A
-%09%09%09%09%0A%09%09%09%09JSONObject r = new JSONObject();%0A%09%09%09%09r.put(%22cid%22, this.getCellID());%0A%09%09%09%09
+%0A%09%09%09this.getCID(
 call
@@ -968,22 +968,11 @@
 text
-.success(r
 );%0A
-%09
 %09%09%09r
@@ -989,56 +989,10 @@
 ;%0A%09%09
-%09
 %7D%0A
-%09%09%09callbackContext.error(%22Invalid action%22);%0A%09
 %09%09re
@@ -1007,178 +1007,64 @@
 se;%0A
-%09%09%7D catch (Exception e) %7B%0A%09%09%09System.err.println(%22Exception: %22 + e.getMessage());%0A%09%09%09callbackContext.error(e.getMessage());%0A%09%09%09return false;%0A%09%09%7D%0A%09%7D%0A%0A%09public int getCellID(
+%0A%09%7D%0A%0A%09public void getCID(CallbackContext callbackContext
 ) th
@@ -1151,16 +1151,21 @@
 tivity()
+%0A%09%09%09%09
 .getAppl
@@ -1180,16 +1180,21 @@
 ontext()
+%0A%09%09%09%09
 .getSyst
@@ -1363,30 +1363,141 @@
 llID
-+
+ + 
 %22%22);%0A%09%09
-return c
+if (cellID != null) %7B%0A%09%09%09callbackContext.success(cellID + %22%22);%0A%09%09%7D else %7B%0A%09%09%09callbackContext.error(%22C
 ell
+ 
 ID
-;
+ is null%22);%0A%09%09%7D%0A
 %0A%09%7D%0A

Update LocationInfo.java