-->

Inflate layout in Xposed module

2019-09-07 01:41发布

问题:

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?

回答1:

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);