1
votes

I want to get sim serial number in codename one using Android native code, following is my native implementation class, I have also added permission in build hint, code doesn't give any error but return null

    import com.codename1.impl.android.AndroidNativeUtil;
    import android.telephony.TelephonyManager;

    public class MyNativeImpl {

            public String simID() {
            TelephonyManager tMgr=(TelephonyManager) AndroidNativeUtil.getActivity().getSystemService("phone");        
            String SIMSerialNumber=tMgr.getSimSerialNumber();  
                 return SIMSerialNumber;
            }

             public boolean isSupported() {
                return true;
            }
    }

I have added this code,

if(!AndroidNativeUtil.checkForPermission(Manifest.permission‌​.READ_PHONE_STATE, "This should be the description shown to the user...")){ your code here }

but getting error like

error: package Manifest does not exist if(!AndroidNativeUtil.checkForPermission(Manifest.permission.READ_PHONE_STATE, "App requires the permission to work properly")) ^ Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error

2

2 Answers

1
votes

There's a library written by Fabricio Cabeca a while ago for that.

Search the Codename Extensions Library for Telephony (Right-click project -> Codename One -> CodenameOne Settings -> Extensions). Use this cn1LIb.

If there's still an issue with Android below 6.0,

add android.xpermissions=<uses-permission android:name="android.permission.READ_PHONE_STATE"/> to your build hint.

And also make sure you're not testing on Dual sim device as this could problematic.

0
votes

I think sim serial Number and sim number is unique. You can try this for get sim serial number and get sim number and Don't forget to add permission in manifest file.

TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String getSimSerialNumber = telemamanger.getSimSerialNumber();
String getSimNumber = telemamanger.getLine1Number();

And add below permission into your Androidmanifest.xml file.

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>