when use for-each to do some things
for example
package io.flutter.plugins;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import java.util.List;
import tool.sport.sport_app.R;
import static android.content.Context.SENSOR_SERVICE;
public class MainActivityLaunch extends AppCompatActivity implements SensorEventListener {
private SensorManager mSensorManager ;
private Sensor mAcceleromet;
private List<Sensor> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
mAcceleromet = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
list=mSensorManager.getSensorList(Sensor.TYPE_ALL);
System.out.println(" --------------------1------------------------ ") ;
System.out.println(" ---------------------2----------------------- ") ;
System.out.println(" ---------------------3----------------------- ") ;
System.out.println(" ---------------------4----------------------- ") ;
System.out.println(" -----------------------5--------------------- ") ;
for(int i=0;i< list.size();i++){
Log.d(""+list.get(i).getName(),"--------------------------------------------"+ " liuzhiwei " );
}
System.out.println(" ---------------------<<<<<<<<<6->>>>>>>>>>---------------------- ") ;
System.out.println(" -----------------------<<<<<<<<7->>>>>>>>>>>>-------------------- ") ;
try {
for(Sensor sensor:list ){
Log.d("","--------qqqqqqq-----------"+sensor.getName() );
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(" -------------------8------------------------ ") ;
System.out.println(" ------------------9-------------------------- ") ;
System.out.println(" -------------------10------------------------- ") ;
System.out.println(" --------------------11------------------------ ") ;
System.out.println(" --------------------12------------------------ ") ;
System.out.println(" -------------------------------------------- ") ;
System.out.println(" -------------------------------------------- ") ;
System.out.println(" -------------------------------------------- ") ;
System.out.println(" -------------------------------------------- ") ;
}
protected void onResume(){
super.onResume();
mSensorManager.registerListener(this,mAcceleromet,SensorManager.SENSOR_DELAY_NORMAL);
}
protected void onPause(){
super.onPause();
mSensorManager.unregisterListener(this);
}
/**
* Called when there is a new sensor event. Note that "on changed"
* is somewhat of a misnomer, as this will also be called if we have a
* new reading from a sensor with the exact same sensor values (but a
* newer timestamp).
*
* <p>See {@link SensorManager SensorManager}
* for details on possible sensor types.
* <p>See also {@link SensorEvent SensorEvent}.
*
* <p><b>NOTE:</b> The application doesn't own the
* {@link SensorEvent event}
* object passed as a parameter and therefore cannot hold on to it.
* The object may be part of an internal pool and may be reused by
* the framework.
*
* @param event the {@link SensorEvent SensorEvent}.
*/
@Override
public void onSensorChanged(SensorEvent event) {
}
/**
* Called when the accuracy of the registered sensor has changed. Unlike
* onSensorChanged(), this is only called when this accuracy value changes.
*
* <p>See the SENSOR_STATUS_* constants in
* {@link SensorManager SensorManager} for details.
*
* @param sensor
* @param accuracy The new accuracy of this sensor, one of
* {@code SensorManager.SENSOR_STATUS_*}
*/
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
for each can not output anythings about log in android studio
for loop can output
09-18 11:51:40.213 2568-2568/tool.sport.sport_app I/System.out: --------------------1------------------------
09-18 11:51:40.213 2568-2568/tool.sport.sport_app I/System.out: ---------------------2-----------------------
09-18 11:51:40.213 2568-2568/tool.sport.sport_app I/System.out: ---------------------3-----------------------
09-18 11:51:40.213 2568-2568/tool.sport.sport_app I/System.out: ---------------------4-----------------------
09-18 11:51:40.213 2568-2568/tool.sport.sport_app I/System.out: -----------------------5---------------------
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/MPU6500 Acceleration Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/MPU6500 Gyroscope Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/MPU6500 Uncalibrated Gyroscope Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/AK09911C Magnetic field Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/AK09911C Magnetic Sensor UnCalibrated: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/Barometer Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/TMG399X Proximity Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/TMG399X RGB Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/MPL Rotation Vector: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/MPL Game Rotation Vector: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/SAMSUNG Step Detector Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/SAMSUNG Step Counter Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/SAMSUNG Significant Motion Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/Screen Orientation Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/Orientation Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/Gravity Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app D/Linear Acceleration Sensor: -------------------------------------------- liuzhiwei
09-18 11:51:40.213 2568-2568/tool.sport.sport_app I/System.out: ---------------------<<<<<<<<<6->>>>>>>>>>----------------------
09-18 11:51:40.213 2568-2568/tool.sport.sport_app I/System.out: -----------------------<<<<<<<<7->>>>>>>>>>>>--------------------
09-18 11:52:03.703 2568-2568/tool.sport.sport_app I/System.out: -------------------8------------------------
09-18 11:52:03.703 2568-2568/tool.sport.sport_app I/System.out: ------------------9--------------------------
09-18 11:52:03.703 2568-2568/tool.sport.sport_app I/System.out: -------------------10-------------------------
09-18 11:52:03.703 2568-2568/tool.sport.sport_app I/System.out: --------------------11------------------------
09-18 11:52:03.703 2568-2568/tool.sport.sport_app I/System.out: --------------------12------------------------
09-18 11:52:03.713 2568-2568/tool.sport.sport_app I/System.out: --------------------------------------------
09-18 11:52:03.713 2568-2568/tool.sport.sport_app I/System.out: --------------------------------------------
09-18 11:52:03.713 2568-2568/tool.sport.sport_app I/System.out: --------------------------------------------
09-18 11:52:03.713 2568-2568/tool.sport.sport_app I/System.out: --------------------------------------------
09-18 11:52:03.733 2568-2568/tool.sport.sport_app D/SensorManager: registerListener :: 0, MPU6500 Acceleration Sensor, 200000, 0,
09-18 11:52:03.753 2568-2568/tool.sport.sport_app D/SecWifiDisplayUtil: Metadata value : none
09-18 11:52:03.773 2568-2568/tool.sport.sport_app D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{4f01ee2 I.E...... R.....ID 0,0-0,0}
09