Inflate layout in Xposed module

落爺英雄遲暮 提交于 2019-12-13 03:34:58

问题


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


来源:https://stackoverflow.com/questions/27869535/inflate-layout-in-xposed-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!