android getSystemService error with extends BroadcastReceiver -


i have 2 activities

public class mainactivity extends appcompatactivity {

.............. @override protected void oncreate(bundle savedinstancestate) { .............. .............. } 

}

public class incomingsms extends broadcastreceiver{

public void onreceive(context context, intent intent){ .............. .............. }

public string getcelldata() {

telephonymanager telephonymanager = (telephonymanager) getsystemservice(context.telephony_service); gsmcelllocation celllocation = (gsmcelllocation) telephonymanager.getcelllocation();

.............. .............. 

return somestring; }

i want return string getcelldata public void onreceive. there error on getsystemservice in getcelldata(). can do. thanks.

getsystemservice() method on context. broadcastreceiver not inherit context. however, passed context onreceive(). so, call getsystemservice() on context parameter.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -