简体   繁体   中英

LED flash light activation

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".

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM