发表于: 2018-11-20 17:47:55
0 941
一、今天完成的事情
获取当前设备所有的传感器
源码中的Seneor类有如下实例域
/* Some of these fields are set only by the native bindings in
* SensorManager.
*/
private String mName;
private String mVendor;
private int mVersion;
private int mHandle;
private int mType;
private float mMaxRange;
private float mResolution;
private float mPower;
private int mMinDelay;
private int mFifoReservedEventCount;
private int mFifoMaxEventCount;
private String mStringType;
private String mRequiredPermission;
private int mMaxDelay;
private int mFlags;
private int mId;
具体实现
/**
* 获取当前设备所有传感器的具体情况
*/
public void getAllSensorsSituation() {
List<Sensor> sensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);
StringBuilder sb = new StringBuilder();
sb.append("该机共有" + sensors.size() + "个传感器");
int i = 1;
String s;
for (Sensor sensor : sensors) {
sb.append("\n" + i);
sb.append("\n名称:" + sensor.getName());
sb.append("\n供应商:" + sensor.getVendor());
sb.append("\n版本:" + sensor.getVersion());
if (Build.VERSION.SDK_INT < 20) {
sb.append("\n类型:" + sensor.getType());
} else {
s = sensor.getStringType();
sb.append("\n类型:" + (s.substring(s.lastIndexOf(".") + 1)).toUpperCase());
}
sb.append("\n######");
i += 1;
}
Log.i(TAG, "getAllSensorsSituation: " + sb.toString());
}
在Fragment中修改Activity中的ToolBar的menu
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//指明fragment愿意添加item到选项菜单(否则, fragment将接收不到对 onCreateOptionsMenu()的调用)
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.local_video_menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.take_video:
takeVideo();
break;
case R.id.refresh:
initVideo();
break;
default:
break;
}
return true;
}
二、明天计划的事情
事假
三、遇到的问题
四、收获
评论