I am creating a module that extends from another class but i need to use getBaseContext(). how can I use it in my own module? If I have to run the activity then how to do that if not how to solve the problem thanks
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 ;
}
}
Change GetTelco
to include a context param. Then call it using your available context from anywhere
public String GetTelco(final Context context)
{
TelephonyManager tm =(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String operatorName = tm.getNetworkOperatorName();
}
Example of calling it:
someView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String telcoName = myTelcoInstance.GetTelco(v.getContext())
}
});
What about...
Context ctx = getActivity().getApplicationContext();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With