From which SDK level is android.intent.action.SIM_

2019-09-16 15:32发布

问题:

I have an app in the market (SIM Locked Notifier) that relies on a broadcast receiver that reacts upon receiving a broadcast intent for *android.intent.action.SIM_STATE_CHANGED*.. I developed the app for the latest version, 4.0.3 (i.e. SDK level 15) and now I'd like to extend its compatibility to lower levels (providing runtime checks for unavailable things, like action bar or preference fragments)... The problem is that I'd like to understand if the *SIM_STATE_CHANGED* event is generated also on older platforms.. This intent is undocumented, it is not even found within the *platforms/android-15/data/broadcast_actions.txt* within the SDK.. Should I dig into the sources to understand where it is implemented and down to which SDK level? Is this a vendor-specific event? I have an HTC One X on which it works.

回答1:

I am not sure about your first question.But i can help you out in answering Second question.

and now I'd like to extend its compatibility to lower levels (providing runtime checks for unavailable things, like action bar or preference fragments)

Reflection will help you out in this case. Using reflection you can query class for available methods,constructors etc.

Suppose you want to use PopupMenu in your application.And it may be the case that you application still want to run on pre 4.0 devices.So use reflection

Following code snippet and bit of Google search will help you out.

String sClassName = "android.widget.PopupMenu";  
    try {  
        Class classToInvestigate = Class.forName(sClassName);   
        Yes!!! Class is aviliable now do whatever you want to do with PopupMenu.
        // Dynamically do stuff with this class  
        // List constructors, fields, methods, etc.  

    } catch (ClassNotFoundException e) {  
        // Class not found!  
        it means application is running on pre 4.0 version device.
    } catch (Exception e) {  
        // Unknown exception  
    }