Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,808,261 Members 37,994 Now Online
XDA Developers Android and Mobile Development Forum

Different parameters for specific OS version

Tip us?
 
pyler
Old
#1  
Senior Member - OP
Thanks Meter 440
Posts: 357
Join Date: Jan 2013
Default Different parameters for specific OS version

I have code like this:
XposedHelpers.findAndHookMethod(packageManagerServ ice, null,
"anything", String.class, Integer.class, Integer.class, new XC_MethodHook() {

How can I change bolded code for specific Android Version?

For example:
if Android version is lower than JB MR2 then params = String.class, Integer.class, Integer.class, Integer.class else params = String.class, Integer.class, Integer.class

?
 
GermainZ
Old
(Last edited by GermainZ; 4th August 2014 at 01:26 AM.)
#2  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,387
Posts: 5,472
Join Date: Aug 2012
Either pass the array of classes to e.g. findAndHookMethod, or define the hook and use different findAndHookMethod calls with the arguments you want.

Code:
Object[] argumentClasses;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
    argumentClasses = new Object[]{argumentClass1, argumentClass2};
else
    argumentClasses = new Object[]{argumentClass1};
findAndHookMethod(class, method, argumentClasses, hook);
Or:
Code:
XC_MethodHook hook = new XC_MethodHook() {
    @Override
        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
            // Hook
        }
};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
    findAndHookMethod(class, method, argumentClass1, argumentClass2, hook);
else
    findAndHookMethod(class, method, argumentClass1, hook);
The Following User Says Thank You to GermainZ For This Useful Post: [ Click to Expand ]
 
pyler
Old
#3  
Senior Member - OP
Thanks Meter 440
Posts: 357
Join Date: Jan 2013
Great! Thank you!
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes