Modify GetTelco to include the context parameter. Then call it using your accessible context from anywhere
public String GetTelco(final Context context) { TelephonyManager tm =(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String operatorName = tm.getNetworkOperatorName(); }
An example of its call:
someView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String telcoName = myTelcoInstance.GetTelco(v.getContext()) } });
petey source share