The error is not in your line of code, but where you are calling it. getPackageManager() is a method of Context. You can use this method inside an Activity (because an Activity is a Context), but if you are calling it elsewhere, you need to pass a Context. In a fragment you may also have access to the getActivity() function, which returns the Acitivity-Context.
Context context...;
context.getPackageManager();
getActivity().getPackageManager();