Question

I am trying to use the flash LED that is built into my android device. I found an existing question that was very helpful but I am seeing a strange compile error now. The problem is the part of my code where I check availability of flash.

boolean FlashAvails=Context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

There is a compile error that reads "Cannot make a static reference to a non-static method getPackageManager() from type Context".

Was it helpful?

Solution

The method getPackageManager() is not static, according to the Javadoc: http://developer.android.com/reference/android/content/Context.html

You'll need to get a reference to the context and then you can call the method.

To get a reference to the context you can all:

Context appContext =  Context.getApplicationContext();

Then you can get access to the package manager as follows:

appContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

Make sure to include the import:

import android.content.Context;

Assuming you're using Eclipse, you can press: ctrl-shift-o and it will reorganize your imports and pull in anything that's missing.

If you're still having trouble, another way is to get the Camera Parameters, as described in this posting: How to find flashlight feature is available or not in device < = sdk 4

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top