Java tutorial
//package com.java2s; /** * Appcelerator Titanium Mobile * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the Apache Public License * Please see the LICENSE included with this distribution for details. */ import android.app.Activity; import android.content.Context; import android.hardware.SensorManager; public class Main { private static SensorManager sensorManager; public static boolean hasDefaultSensor(Activity activity, int type) { boolean oneShot = false; boolean result = false; if (sensorManager == null) { oneShot = true; sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); } if (sensorManager != null) { result = (sensorManager.getDefaultSensor(type) != null); if (oneShot) { sensorManager = null; } } return result; } }