检查设备是否具有手电筒 [英] Check if a device has flashlight

查看:200
本文介绍了检查设备是否具有手电筒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class FlashLightActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);

        Context context = this;
        PackageManager packageManager = context.getPackageManager();

        // if device support camera?
        if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
            //yes
            Log.i("camera", "This device has camera!");
        }else{
            //no
            Log.i("camera", "This device has no camera!");
        }


    }
}

这是一个工作code检查的天气应用程序手电筒或没有,但我怎么能在<$ C $使用code C> appwidgetprovider ?

This is a working code for Checking weather the application has FlashLight or not , but how can I use this code in an appwidgetprovider ?

推荐答案

如果你刨去使用它的函数内部像的onUpdate onEnabled Appwidgetprovider 的等,那么所有这些功能有背景作为输入参数。您可以使用此背景下,使用软件包管理系统,你在这里做。

If you are planing to use it inside any function like onUpdate or onEnabled etc of Appwidgetprovider, then all those functions have context as a input parameter. You can use that context for using PackageManager as you are doing here.

另外,在你的问题你提到的 手电筒 的。所以只是检查,如果你需要 FEATURE_CAMERA_FLASH FEATURE_CAMERA

Also in your question you mention flashlight. So just check if you need FEATURE_CAMERA_FLASH or FEATURE_CAMERA.

Context context = this;
PackageManager packageManager = context.getPackageManager();

// if device support flash?
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
    //yes
    Log.i("camera", "This device has flash supported!");
}else{
    //no
    Log.i("camera", "This device has no flash support!");
}

希望它帮助。

这篇关于检查设备是否具有手电筒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆