How to reflect SubscriptionManager and Telephonymanager get their methods

Source: Internet
Author: User
        Mtelephonymanager = (Telephonymanager) context.getsystemservice (context.telephony_service);
        if (Mtelephonymanager = = null) {
            throw new Error ("telephony manager is null");
        }
       
        Msubscriptionmanager = Subscriptionmanager.from (Mcontext);

For a chestnut, get Subscriptionmanagergetsubid (SlotID) and Telephonymanager's getsimserialnumber (int subId)

    private static int[] getsubid (int slotid) {Method declaredmethod;
        int[] Subarr = null; try {Declaredmethod = Class.forName ("Android.telephony.SubscriptionManager"). Getdeclaredmethod ("Getsubid", NE
            W Class[]{integer.type});
            Declaredmethod.setaccessible (TRUE);
        Subarr = (int[]) Declaredmethod.invoke (Msubscriptionmanager, SlotID);
            } catch (ClassNotFoundException e) {e.printstacktrace ();
        Declaredmethod = null;
            } catch (IllegalArgumentException E2) {e2.printstacktrace ();
        Declaredmethod = null;
            } catch (Nosuchmethodexception E3) {e3.printstacktrace ();
        Declaredmethod = null;
            } catch (ClassCastException e4) {e4.printstacktrace ();
        Declaredmethod = null;
            } catch (Illegalaccessexception e5) {e5.printstacktrace ();
        Declaredmethod = null; } catch (InvocationtargetexcEption e6) {e6.printstacktrace ();
        Declaredmethod = null;
        } if (Declaredmethod = = null) {Subarr = null;
        } mlog.d ("getsubid =" + subarr[0]);
    return Subarr;
        } private String Getsimserialnumber (int subId) {method method;
        String status = NULL;
            try {method = Mtelephonymanager.getclass (). GetMethod ("Getsimserialnumber", Int.class);
            Method.setaccessible (TRUE);
        Status = String.valueof (Method.invoke (Mtelephonymanager, subId));
        } catch (Nosuchmethodexception e) {e.printstacktrace ();
        } catch (Illegalaccessexception e) {e.printstacktrace ();
        } catch (IllegalArgumentException e) {e.printstacktrace ();
        } catch (InvocationTargetException e) {e.printstacktrace ();
        } mlog.d ("Getsimserialnumber =" + status);
    return status; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.