Cilenco Cilenco - 1 year ago 103
Android Question

Inflate layout in Xposed module

At the moment I'm writing a module for the Xposed framework but now I have a problem. I want to inflate a layout from my own package. I thought I can do this by using this code:

Context context = (Context) XposedHelpers.getObjectField(object, "mContext");

LayoutInflater inflater = LayoutInflater.from(context);
View buttons = inflater.inflate(R.layout.volumebuttons, null, false);

But this does not work. When it comes to the third line an exception is thrown (sorry for this unclear formulation. I do not realy know what a kind of exception is thrown - I can't see it with the Xposed framework). Do you have any ideas why I can't use this code to inflate my layout?

Answer Source

I fund out it works. I realy had to create a context object for my application. For everyone how is looking for that here is the code with which you can do this:

Context context = (Context) XposedHelpers.getObjectField(object, "mContext");
context = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download