Thursday 10 January 2013

Android : How To Check If Device Has Camera

In Android, you can use PackageManager , hasSystemFeature() method to check if a device has camera, gps or other features.

See full example of using PackageManager in an activity class.


package com.mkyong.android;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;

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!");
}

}
}



Camera flashlight example
You may interest on this example – How to turn on/off camera LED/flashlight in Android.

1 comment:

  1. I think the admin of this web page is in fact working hard
    in support of his site, since here every data is quality
    based data.

    ReplyDelete