How to programatically check phone is wifi capable?
How can I programatically check phone is wifi capable?
I'm NOT talking about enabling/disa开发者_如何学编程bling wifi. I want to get the presence of a wifi hardware/driver
boolean hasWifi = PackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI);
PackageManager p = ctx.getPackageManager();
boolean hasWifi = p.hasSystemFeature(PackageManager.FEATURE_WIFI);
Check the documentation for further hardware constants that you can test. ctx
is a Context instance.
Edit: Sniff, forgot the correct way to use it, fixed my example.
PackageManager manager = getPackageManager();
FeatureInfo info[] = manager.getSystemAvailableFeatures();
for(int i=0; i<info.length; i++){
if(((info[i].name)!=null)&&(info[i].name).equals("android.hardware.wifi")){
Toast.makeText(getBaseContext(), "Support wifi", Toast.LENGTH_LONG).show();
hope this will help you
精彩评论