Reputation: 626
I'm building a flashlight app and I've learned that when I call
this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)
,
the Nexus 7 returns true and when asking for the FlashModes()
the size is 1 and the option is called "off." So when I check whether or not flash exists on devices, if the device lies about it, I can run into trouble. I've added !android.os.Build.MODEL.equals("Nexus 7")
to my if statement to prevent crashing my app while testing on my Nexus 7.
If there are other devices that lie about having a flash, my app will likely crash on them. How can I avoid this?
Upvotes: 0
Views: 519
Reputation: 13917
you can implement a double check
after calling
this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)
check if
getSupportedFlashModes() returns null
if no
check if
flash modes only contains one entry "off"
Upvotes: 1