Android传感器高级编程

原文链接:https://my.oschina.net/u/856019/blog/181292

Android传感器高级编程


手机设备中的传感器让应用的可玩性大大增加,提供了各种创新的交互方式,以及在PC上很难实现的功能。如果想要创建真正了不起的Android 应用,就必须知道如何利用Android的所有功能。本书会利用你所需的知识和代码来武装你,帮助你很好地利用Android中的传感器。


对其内容详细阅读


转载于:https://my.oschina.net/u/856019/blog/181292

展开阅读全文
博主设置当前文章不允许评论。

android传感器求助

08-17

我一运行如下代码在getSystemService时就会奔溃。rn[code=Java]rnpackage com.example.switchkeyboard;rnrnrnrnimport org.openintents.sensorsimulator.hardware.SensorEvent;rnimport org.openintents.sensorsimulator.hardware.SensorEventListener;rnimport org.openintents.sensorsimulator.hardware.SensorManagerSimulator;rnrnrnrnrnrnimport android.os.Bundle;rnimport android.app.Activity;rnimport android.view.Menu;rnrnrnimport android.widget.Button;rnimport android.widget.TextView;rnrnpublic class MainActivity extends Activity rn MyListener myListener;rn Button Open=null;rn Button Close=null;rnrn org.openintents.sensorsimulator.hardware.Sensor sor=null;rn SensorManagerSimulator imulatorManager;rn TextView textView=null;rn @Overridern public void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_main);rn rn Open=(Button)findViewById(R.id.open);rn Close=(Button)findViewById(R.id.close);rn textView=(TextView)findViewById(R.id.textView);rn // senM=(SensorManager)getSystemService(Context.SENSOR_SERVICE);rn //一运行到这里就奔溃rn imulatorManager=SensorManagerSimulator.getSystemService(this,SENSOR_SERVICE);rn /* imulatorManager.connectSimulator();rn //sor=imulatorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);rn rn // sor=(Sensor)imulatorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);rn rn myListener=new MyListener();rn rn rn Open.setOnClickListener(new Button.OnClickListener()rn rn @Overridern public void onClick(View arg0) rn // TODO Auto-generated method stubrn rn imulatorManager.registerListener(myListener, imulatorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST);rn rn rn rn );rn*/rn rn rnrn rn class MyListener implements SensorEventListener rn rn rn public MyListener() rn // TODO Auto-generated constructor stubrn rn @Overridern public void onSensorChanged(SensorEvent arg0) rn // TODO Auto-generated method stubrn rn textView.setText(arg0.values[0]+"");rn rn rnrn @Overridern public void onAccuracyChanged(rn org.openintents.sensorsimulator.hardware.Sensor arg0, int arg1) rn // TODO Auto-generated method stubrn rn rn rn rn rn@Overridernprotected void onPause() rn // TODO Auto-generated method stubrn super.onPause();rn imulatorManager.unregisterListener(myListener);rnrn rn rn rn rn @Overridern public boolean onCreateOptionsMenu(Menu menu) rn getMenuInflater().inflate(R.menu.activity_main, menu);rn return true;rn rnrn[/code]rn挺纳闷的。rn现在没有头绪。会不会是原本我环境配置不好?但是只有在SensorManagerSimulator.getSystemService才会出错?rn还望大家说说可能性 论坛

没有更多推荐了,返回首页