Android Sensor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Sensor class.

This code example shows how to use the following methods:getMaximumRange, getMinDelay, getName, getPower, getResolution
	/** 
	 * set Sensor information from Sesnsor object 
	 * @param sensor 
	 */ 
	public void autoSetSensorInfo(Sensor sensor){
		sensorInfo.put("MaximumRange", sensor.getMaximumRange());
		sensorInfo.put("MinDelay",sensor.getMinDelay());
		sensorInfo.put("Name",sensor.getName());
		sensorInfo.put("Power",sensor.getPower());
		sensorInfo.put("Resolution",sensor.getResolution());
		sensorInfo.put("Type",sensor.getType());
		sensorInfo.put("Vendor",sensor.getVendor());
		sensorInfo.put("Version",sensor.getVersion());
	} 
} 
6
CodeRank
This code example shows how to use the following methods:getMaximumRange, getPower, getResolution, getVendor, getVersion
		return sensorevent;
	} 
	public static void PrintSensorDetails(Sensor sensor) {
		Log.i(TAG, "SensorHandler -> PrintSensorDetails");
		Log.d(TAG, String.format("\t getName()=%s", sensor.getName()));
		Log.d(TAG, String.format("\t getMaximumRange()=%f", sensor.getMaximumRange()));
		Log.d(TAG, String.format("\t getPower()=%fmA", sensor.getPower()));
		Log.d(TAG, String.format("\t getResolution()=%f", sensor.getResolution()));
		Log.d(TAG, String.format("\t sensor.getType()=%d", sensor.getType()));
		Log.d(TAG, String.format("\t getVendor()=%s", sensor.getVendor()));
		Log.d(TAG, String.format("\t getVersion()=%d", sensor.getVersion()));
	} 
	public String GetSensorEventString() { 
		String str =  String.format(
			"\t sensor.getName()=%s\n" + 
			"\t sensor.getType()=%d\n" + 
			"\t accuracy=%d\n" + 
			"\t timestamp=%d\n" + 
			"\t values.length=%d\n", 
			sensorevent.sensor.getName(),
6
CodeRank
This code example shows how to use the following methods:getMaximumRange, getMinDelay, getName, getPower, getResolution
			y = se.values[SensorManager.DATA_Y]; 
			z = se.values[SensorManager.DATA_Z]; 
 
			// 设置显示文字 
			textView_sensor.setText("距离感应:" + "\n" + "x=" + x + "\n" + "y=" + y 
					+ "\n" + "z=" + z + "\n\n" + "Name:" + sensor.getName() 
					+ "\n" + "Type:" + sensor.getType() + "\n" + "Version:" 
					+ sensor.getVersion() + "\n" + "vendor:" 
					+ sensor.getVendor() + "\n" + "MAXrange:" 
					+ sensor.getMaximumRange() + "\n" + "MinDelay:" 
					+ sensor.getMinDelay() + "\n" + "power:" 
					+ sensor.getPower() 
					// getMinDelay()Added in API level 9 
					+ "\n" + "Resolution:" + sensor.getResolution() + "\n"); 
 
			if (x == 0) { 
				textView_sensor.setBackgroundColor(0xff000000);// 设背景颜色为黑 
			} else if (x == 1) { 
				textView_sensor.setBackgroundColor(0xff0000ff);// 设背景颜色为蓝 
			} else { 
6
CodeRank
This code example shows how to use the following methods:getMaximumRange, getName, getResolution, getVendor
        mTextValue = (TextView)findViewById(R.id.textSensorValue);
        mTextFace = (TextView)findViewById(R.id.textSensorExpression);
    } 
 
    private void ShowSensorValues() { 
        mTextName.setText("Sensor name: " + mProxSensor.getName());
        mTextVendor.setText("Sensor vendor: " + mProxSensor.getVendor());
        mTextResolution.setText("Sensor resolution: " + mProxSensor.getResolution());
        mTextMaxRange.setText("Sensor maximum range: " + mProxSensor.getMaximumRange());
    } 
 
    @Override 
    protected void onResume() { 
        Log.d(TAG, "onResume()");
        super.onResume(); 
 
        mProxSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
        mSensorManager.registerListener(this, mProxSensor,
                                        SensorManager.SENSOR_DELAY_NORMAL);
        ShowSensorValues(); 
6
CodeRank
This code example shows how to use the following methods:getMaximumRange, getMinDelay, getName, getPower, getResolution
     
    public void updateWidgetValues() { 
        updateHumanReadableNameWidget(); 
        updateRealtimeDataTitle(); 
        updateRealtimeLabels(); 
        sensorNameView.setText(sensor.getName());
        sensorTypeView.setText(String.format("%d", sensor.getType()));
        sensorVendorView.setText(sensor.getVendor());
        sensorVersionView.setText(String.format("%d", sensor.getVersion()));
        sensorPowerUseView.setText(String.format("%,04.2f", sensor.getPower()));
        sensorResolutionView.setText(String.format("%,4.2f", sensor.getResolution()));
        sensorMaxRangeView.setText(String.format("%,4.2f", sensor.getMaximumRange()));
        sensorMinDelayView.setText(String.format("%,4.2f", Double.valueOf(sensor.getMinDelay()).doubleValue()));
    } 
     
    private void updateRealtimeDataTitle() { 
        String text = getString(R.string.sensor_realtime_title_msg, sensor.getName());
        basicSensorRealtimeDataTitle.setText(text);
    } 
     
6
CodeRank
This code example shows how to use the following methods:getName
    @Override 
    public void onAccuracyChanged(Sensor sensor, int accuracy)
    { 
        Log.d(TAG,
                String.format("Accuracy for sensor %s = %d",
                sensor.getName(), accuracy));
    } 
     
    /** 
     * Generates a rotation matrix using the member data stored in 
     * accelerationValues and magneticValues. 
     *  
     * @return The rotation matrix returned from 
     * {@link android.hardware.SensorManager#getRotationMatrix(float[], float[], float[], float[])} 
     * or <code>null</code> if either <code>accelerationValues</code> or 
     * <code>magneticValues</code> is null. 
     */ 
    private float[] generateRotationMatrix() 
    { 
        float[] rotationMatrix = null;
5
CodeRank
This code example shows how to use the following methods:getMaximumRange, getName, getPower, getResolution
			boolean gyroscopeExists = getPackageManager().hasSystemFeature(PackageManager.FEATURE_SENSOR_GYROSCOPE);
			 
			if (gyroscopeExists){
				 
				mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
				mInfo = String.format("Name:%s, maxRange:%f, Resolution>%f, Power:%f", mGyroscope.getName(), mGyroscope.getMaximumRange(), mGyroscope.getResolution(), mGyroscope.getPower());
				 
			} 
			 
			break; 
		} 
		 
		} 
		 
		return mInfo;
		 
	} 
	 
	 
	private String getCellularInfo(){
5
CodeRank
This code example shows how to use the following methods:getName, getVendor, getVersion
 
    private static String getSensorDescription(int sensorType)
    { 
        try { 
            Sensor s  = m_sensorManager.getDefaultSensor(sensorType);
            return s.getName() + " " + s.getVendor() + " v" + s.getVersion();
        } catch(Exception e) {
            e.printStackTrace();
        } 
        return null; 
    } 
 
    private static int[] getSensorList() 
    { 
        try { 
            List<Sensor> list = m_sensorManager.getSensorList(Sensor.TYPE_ALL);
            HashSet<Integer> filteredList = new HashSet<Integer>();
            for (Sensor s : list)
                filteredList.add(s.getType());
            int retList[] = new int[filteredList.size()];
5
CodeRank
This code example shows how to use the following methods:getName
	 
	/** 
	 * {@inheritDoc} 
	 */ 
	public String getName() {
		return this.sensor.getName();
	} 
	 
	/** 
	 * {@inheritDoc} 
	 */ 
	public float getPowerUsage() { 
		return this.sensor.getPower();
	} 
} 
4
CodeRank
This code example shows how to use the following methods:getName
	public void startFile(){ 
		finishFile(); 
		 
		firstEntry=-1;
		started = System.currentTimeMillis();
		String name=Detector.getId(detector)+"_"+typeName+"_"+sensor.getName()+"_"+dateFormat.format(new Date(started));
		 
		currentFile=new File(
				logFolder,
				name+".zip"
		); 
		try { 
			ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(currentFile));
			ZipEntry entry = new ZipEntry(name+".log");
			entry.setTime(started);
			zout.putNextEntry(entry);
			out = new DataOutputStream(zout);
			logHeader(); 
		} catch (IOException e) {
			e.printStackTrace();
4
CodeRank

Related Android Sensor Questions & Answers:

Other Android Sensor Examples

14:	  private static SensorManager sensorService;
15:	  private MyCompassView compassView;
16:	  private Sensor sensor;
17:	
18:	  /** Called when the activity is first created. */

Read More