2015-09-23 38 views
0

该应用程序要求用户覆盖接近传感器以开始录音, ,当用户揭开接近传感器时,应停止录制,并打开稍后播放声音的另一活动。用于音频录制的Android接近传感器

@Override 
public void onSensorChanged(SensorEvent event) { 



    if(event.values[0] == 0){ 
     proximity.setText(R.string.grav2); 
     startRecording(); 
     /* if(event.values[0] == 0) { 
      stopRecording(); 
      Intent intent = new Intent(this, reprodutor.class); 
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      startActivity(intent); 
     }*/ 

    } 
} 

我的问题是与这块代码,当我覆盖传感器开始和停止记录。请帮忙!

+0

我认为接近传感器捕捉只有NewIntent(包括传感器)和发起onSensorChanges开始录制,但由于没有完成接近传感器的逻辑,它超时 - 这就是为什么你失去了连接。我的假设。 –

回答

0

我是个初学者,但一些,虽然我设法在这里找到一个解决方案。它是任何人谁在这个同样的问题绊倒:

@Override 
public void onSensorChanged(SensorEvent event) { 



    if(event.values[0] == 0){ 
     proximity.setText(R.string.grav2); 
     startRecording(); 
     flag = true; 
     /* if(event.values[0] == 0) { 
      stopRecording(); 
      Intent intent = new Intent(this, reprodutor.class); 
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      startActivity(intent); 
     }*/ 

    }else{ 
     if(flag == true){ 
      stopRecording(); 
      Intent intent = new Intent(this, reprodutor.class); 
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      startActivity(intent); 

     } 

    } 
}