0

We want to get the IMSI number for the mobile device in order to find out if the user is registered to use particular application or not.

I did search on the net. It say Worklight is using Cordova. It gives UUID and device name /description but not IMSI number.

I am trying this code here. but the cordova always goes to getfailure. and says Class Not Found. I am using IBM Worklight

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;

import org.json.JSONArray;
import org.json.JSONException;
import android.provider.Settings;
import android.content.Context;
import android.telephony.TelephonyManager;



   @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

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

            org.json.JSONObject r = new org.json.JSONObject();

            TelephonyManager tManager = (TelephonyManager) cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);            

            r.put("imei", "sampleimei");
            r.put("imsi", "sampleimsi123");
            r.put("tmanagerimsi", tManager.getSimSerialNumber());
            r.put("deviceModal", this.getModel() );

            callbackContext.success(r);

            return true;

        } 
        else {

            return false;

        }

    }

javascript:

function getImei(){
    alert("inside getImei");
    cordova.exec(getSuccess, getFailure, "DeviceDetails", "imeiNumber", []);
}

function getSuccess(data){
    alert(data.imei +" "+data.imsi+" "+data.tmanagerimsi);
}

function getFailure(data){
    alert(data);
    alert(data.imei +" "+data.imsi+" "+data.tmanagerimsi+" "+data.deviceModal);
}
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
svd
  • 43
  • 1
  • 1
  • 5

2 Answers2

1

To get the IMSI number, you will need to create a Cordova plug-in in order to access this information which is stored in the device.

See the following training modules how to create a Cordova plug-in in Worklight:

See the following topics how to get the IMEI number, and similarly the IMSI number. You will then need to combine the two (Cordova plug-in and native code from the above), to get the data you want:

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • hi, how should i access Telephonymanager in worklight. I created android environment and added Telephony class. Now, I donot know how i should access it in worklight common application. – svd Mar 12 '14 at 08:46
  • Did you read the training modules? You need to create a Cordova plug-in and use Native code to access it. – Idan Adar Mar 12 '14 at 08:53
  • hi, i created cordova module. i am able to access cordova device UUID,device name and others as suggested. i have written code. cordova.exec(getSuccess, getFailure, "DeviceDetails", "imeiNumber", []); and created class DeviceDetails but i still get failure. – svd Mar 12 '14 at 10:44
  • "Get failure" is not helpful. What are you getting? Edit the **question** – Idan Adar Mar 12 '14 at 11:11
  • Did you add the .java file to your project? – Idan Adar Mar 13 '14 at 06:29
  • yes, i added the file DeviceDetails.java to the project – svd Mar 13 '14 at 06:36
  • Please upload to Dropbox your Worklight project. – Idan Adar Mar 13 '14 at 06:37
  • hi.. i cannot upload to dropbox. – svd Mar 13 '14 at 06:48
1

Is what you pasted above the full java file? Because it does not seem complete.

You are missing the class declaration. Usually classes in Java are defined like:

public class Dog{
 //stuff
}

I do not see this anywhere in your code.

Also, when installing a plugin you need to modify the config.xml to reflect this.

Please review carefully this guide: http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v610/06_05_Android_-_Adding_native_functionality_to_hybrid_application_with_Apache_Cordova_plugin.pdf

Nathan H
  • 48,033
  • 60
  • 165
  • 247