【发布时间】:2014-01-09 14:59:08
【问题描述】:
我正在创建一个从另一个类扩展的模块,但我需要使用 getBaseContext()。如何在我自己的模块中使用它? 如果我必须运行活动,那么如果不是如何解决问题,该怎么做 谢谢
public class TelcoModule extends KrollModule
{
...
// Methods
@Kroll.method
public String GetTelco()
{
TelephonyManager tm =(TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
String operatorName = tm.getNetworkOperatorName();
return operatorName ;
}
}
【问题讨论】:
-
只需在类的构造函数中传递上下文
-
Context mContext;public TelcoModule(Context context) {mContext =context;// use mContext..}。通过像new TelcoModule(ActivityName.this)