I'm building a android library with some functionality, which will be used by 3rd party apps. Within my library I need to access network related stuff, and need to access Context.getSystemService() to get ConnectivityManager. For e.g. -
ConnectivityManager connectivityManager = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
The problem is that I do not have an activity class, to get context from. So 2 questions -
- Is there a way to get the context of the Activity from which my library method was called?
- Is it is a good practice to ask the app(calling my library) to pass the app's activity context down to a 3rd party library?
Thanks!