android for-each and for different

 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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值