参考文档: 在Service中获得Context

使用方法: Service 本身就是 Context 的实现,所以只需要调用 this,示例代码如下:

1
2
3
4
5
6
/**
* EthernetManager ethernetManager = (EthernetManager) context.getSystemService(
Context.ETHERNET_SERVICE);
*/
EthernetManager ethernetManager = (EthernetManager) this.getSystemService(
Context.ETHERNET_SERVICE);

1. 在AsyncTask中使用context

传入Context,在doInBackground(Context... params){}中调用就好啦。

Android 多线程之IntentService 完全详解

参考文档: https://blog.csdn.net/javazejian/article/details/52426425