WEB开发网
开发学院手机开发Android 开发 Android中的几个System Service 阅读

Android中的几个System Service

 2010-07-01 14:47:00 来源:WEB开发网   
核心提示:1.得到正在运行的Activity列表:ActivityManager activityManager = (ActivityManager)this.mActivity.getSystemService(Context.ACTIVITY_SERVICE);List mAllProcessList = activity

1.得到正在运行的Activity列表:ActivityManager activityManager = (ActivityManager)this.mActivity.getSystemService(Context.ACTIVITY_SERVICE);

List mAllProcessList = activityManager.getRunningAppProcesses();

2.得到手机的动作感应器

//取得SensorManager

SensorManager sensorMgr = (SensorManager)getSystemService(SENSOR_SERVICE);

//返回true表示注册成功,flase则反之

sensorMgr.registerListene(this,SensorManager.SENSOR_ACCELEROMETER,SensorManager.SENSOR_DELAY_GAME);

sensorMgr.unregisterListener(this,SensorManager.SENSOR_ACCELEROMETER);

SensorListener必须实现两个方法:

public void onAccuracyChanged(int arg0, int arg1) {}

public void onSensorChanged(int sensor, float[] values) {}

class Pos3D

{

float x;

float y;

float z;

}

Pos3D cur,last;

cur.x = values[SensorManager.DATA_X];

cur.y = values[SensorManager.DATA_Y];

cur.z = values[SensorManager.DATA_Z];

float speed = Math.abs((cur.x+cur.y+cur.z)-(last.x+last.y+last.z)) //间隔的时间

这样可以得到手机的移动速度

原文:http://andynjux.blogbus.com/logs/67592403.html

Tags:Android System Service

编辑录入:coldstar [复制链接] [打 印]
赞助商链接