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 -

python - Error: Unresolved reference 'selenium' What is the reason? -

php - Need to store a large amount of data in session with CI 3 but on storing large data in session it is itself destorying automatically -