Android Question Little Help With Some Java please !!

Discussion in 'Android Questions' started by potman100, Sep 2, 2015.

  1. potman100

    potman100 Active Member Licensed User

    Hi

    Not really into java and would like to use this code below in B4A :

    Code:
    public static void printTelephonyManagerMethodNamesForThisDevice(Context context) {

        TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Class<?> telephonyClass;
        
    try {
            telephonyClass = Class.forName(telephony.getClass().getName());
            Method[] methods = telephonyClass.getMethods();
            
    for (int idx = 0; idx < methods.length; idx++) {

                System.out.println(
    "\n" + methods[idx] + " declared by " + methods[idx].getDeclaringClass());
            
    }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    The Following code works and returns the sim state :

    Code:
    Dim telMgr As JavaObject = GetContext.RunMethod("getSystemService"Array("phone"))
               
    Dim simState As Int = telMgr.RunMethod("getSimState" , Null)
               
    Log(simState)
    Would appreciate any help.

    Regards

    Potman
     
  2. Johan Schoeman

    Johan Schoeman Expert Licensed User

    DonManfred likes this.
  3. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Here it is compiled to a B4A library. Inline java code will probably not work for earlier B4A versions that do not support inline Java so I have compiled it to a library. It prints the result of the library method from within the library to the B4A log. The library files are in the /files folder of the attached project. Copy them to your additional library folder.

    This is the result printed to the B4A log:

    Code:
    LogCat connected to: c1607b01564cc30
    --------- beginning of /dev/
    log/system--------- beginning of /dev/log/main
    ** 
    Activity (main) Create, isFirst = true **
    public static java.lang.String android.telephony.TelephonyManager.deviceInfo() declared by class android.telephony.TelephonyManager
    public void android.telephony.TelephonyManager.disableLocationUpdates() declared by class android.telephony.TelephonyManager
    public void android.telephony.TelephonyManager.enableLocationUpdates() declared by class android.telephony.TelephonyManager
    public boolean java.lang.Object.equals(java.lang.Object) declared by class java.lang.Object
    public int android.telephony.TelephonyManager.getCallState() declared by class android.telephony.TelephonyManager
    public int android.telephony.TelephonyManager.getCdmaEriIconIndex() declared by class android.telephony.TelephonyManager
    public int android.telephony.TelephonyManager.getCdmaEriIconMode() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getCdmaEriText() declared by class android.telephony.TelephonyManager
    public android.telephony.CellLocation android.telephony.TelephonyManager.getCellLocation() declared by class android.telephony.TelephonyManager
    public final native java.lang.Class java.lang.Object.getClass() declared by class java.lang.Object
    public java.lang.String android.telephony.TelephonyManager.getCompleteVoiceMailNumber() declared by class android.telephony.TelephonyManager
    public int android.telephony.TelephonyManager.getCurrentPhoneType() declared by class android.telephony.TelephonyManager
    public int android.telephony.TelephonyManager.getDataActivity() declared by class android.telephony.TelephonyManager
    public int android.telephony.TelephonyManager.getDataState() declared by class android.telephony.TelephonyManager
    public static android.telephony.TelephonyManager android.telephony.TelephonyManager.getDefault() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getDeviceId() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getDeviceSoftwareVersion() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getIsimDomain() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getIsimImpi() declared by class android.telephony.TelephonyManager
    public [Ljava.lang.String; android.telephony.TelephonyManager.getIsimImpu() declared by class android.telephony.TelephonyManager
    public [Ljava.lang.String; android.telephony.TelephonyManager.getIsimPcscf() declared by class android.telephony.TelephonyManager
    public java.util.HashMap android.telephony.TelephonyManager.getLGUplusKnightInfo() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getLine1AlphaTag() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getLine1Number() declared by class android.telephony.TelephonyManager
    public int android.telephony.TelephonyManager.getLteOnCdmaMode() declared by class android.telephony.TelephonyManager
    public java.util.HashMap android.telephony.TelephonyManager.getMobileQualityInformation() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getMsisdn() declared by class android.telephony.TelephonyManager
    public java.util.List android.telephony.TelephonyManager.getNeighboringCellInfo() declared by class android.telephony.TelephonyManager
    public static int android.telephony.TelephonyManager.getNetworkClass(int) declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getNetworkCountryIso() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getNetworkOperator() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getNetworkOperatorName() declared by class android.telephony.TelephonyManager
    public int android.telephony.TelephonyManager.getNetworkType() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getNetworkTypeName() declared by class android.telephony.TelephonyManager
    public static java.lang.String android.telephony.TelephonyManager.getNetworkTypeName(int) declared by class android.telephony.TelephonyManager
    public int android.telephony.TelephonyManager.getPhoneType() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getSimCountryIso() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getSimOperator() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getSimOperatorName() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getSimSerialNumber() declared by class android.telephony.TelephonyManager
    public int android.telephony.TelephonyManager.getSimState() declared by class android.telephony.TelephonyManager
    public [Ljava.lang.String; android.telephony.TelephonyManager.getSponImsi() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getSubscriberId() declared by class android.telephony.TelephonyManager
    public static java.lang.String android.telephony.TelephonyManager.getUAField() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getVoiceMailAlphaTag() declared by class android.telephony.TelephonyManager
    public java.lang.String android.telephony.TelephonyManager.getVoiceMailNumber() declared by class android.telephony.TelephonyManager
    public int android.telephony.TelephonyManager.getVoiceMessageCount() declared by class android.telephony.TelephonyManager
    public boolean android.telephony.TelephonyManager.hasIccCard() declared by class android.telephony.TelephonyManager
    public native int java.lang.Object.hashCode() declared by class java.lang.Object
    public boolean android.telephony.TelephonyManager.isMultiSimEnabled() declared by class android.telephony.TelephonyManager
    public boolean android.telephony.TelephonyManager.isNetworkRoaming() declared by class android.telephony.TelephonyManager
    public boolean android.telephony.TelephonyManager.isSmsCapable() declared by class android.telephony.TelephonyManager
    public boolean android.telephony.TelephonyManager.isVoiceCapable() declared by class android.telephony.TelephonyManager
    public void android.telephony.TelephonyManager.listen(android.telephony.PhoneStateListener,int) declared by class android.telephony.TelephonyManager
    public final native void java.lang.Object.notify() declared by class java.lang.Object
    public final native void java.lang.Object.notifyAll() declared by class java.lang.Object
    public void android.telephony.TelephonyManager.startMobileQualityInformation() declared by class android.telephony.TelephonyManager
    public void android.telephony.TelephonyManager.stopMobileQualityInformation() declared by class android.telephony.TelephonyManager
    public java.lang.String java.lang.Object.toString() declared by class java.lang.Object
    public final void java.lang.Object.wait() throws java.lang.InterruptedException declared by class java.lang.Object
    public final void java.lang.Object.wait(long) throws java.lang.InterruptedException declared by class java.lang.Object
    public final native void java.lang.Object.wait(long,int) throws java.lang.InterruptedException declared by class java.lang.Object
    ** 
    Activity (main) Resume **
     

    Attached Files:

    Last edited: Sep 2, 2015
    potman100, inakigarm and DonManfred like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice