2015-09-23 25 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); 

     } 

    } 
}