I have problem with my project.
I can't find getPackageManager() method although i imported android.content.pm.PackageManager;
what wrong with this piece of code
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0); .Thanks for your helping
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();
If you are using it in Activity you will not get an error or warning for getPacketManager, but if you are using it in Fragments you should prefix it with getActivity.
example:
PackageManager pm = getActivity().getPackageManager();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With