2
一種新的android。我有一個應用程序正在運行,我正在生成DTMF信號並解釋使用微控制器生成的內容。我正在成功生成音調,但音調正在通過揚聲器播放,我想通過拼接耳機插孔播放音調(所以即使在解決方案之後,我仍然需要忽略android在切換到揚聲器時不希望切換到揚聲器耳機在那裏)。提前致謝。該代碼是在這裏..如何通過我的耳機流式傳輸DTMF音?
package edu.lehigh.cse.paclab.carbot;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ToggleButton;
import android.media.ToneGenerator;
import android.media.AudioManager;
import static android.media.ToneGenerator.TONE_DTMF_0;
import static android.media.ToneGenerator.TONE_DTMF_1;
import static android.media.ToneGenerator.TONE_DTMF_2;
import static android.media.ToneGenerator.TONE_DTMF_3;
import static android.media.ToneGenerator.TONE_DTMF_4;
import static android.media.ToneGenerator.TONE_DTMF_5;
import static android.media.ToneGenerator.TONE_DTMF_6;
public class DTMFActivity extends Activity {
private static final String TAG = "DTMF";
ToggleButton forward;
ToggleButton reverse;
ToggleButton c_clockwise;
ToggleButton clockwise;
ToggleButton pointTurnLeft;
ToggleButton pointTurnRight;
static final ToneGenerator _toneGenerator = new ToneGenerator(AudioManager.STREAM_DTMF, 100);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
forward = (ToggleButton)findViewById(R.id.forward);
reverse = (ToggleButton)findViewById(R.id.reverse);
c_clockwise = (ToggleButton)findViewById(R.id.c_clockwise);
clockwise = (ToggleButton)findViewById(R.id.clockwise);
pointTurnLeft = (ToggleButton)findViewById(R.id.pointTurnLeft);
pointTurnRight = (ToggleButton)findViewById(R.id.pointTurnRight);
}
public void onPause() {
super.onPause();
}
public void onDestroy() {
super.onDestroy();
}
public void forward(View v){
if(!forward.isChecked()){
_toneGenerator.stopTone();
Log.e(TAG, "forward: not emitting");
}
else{
_toneGenerator.startTone(TONE_DTMF_0);
Log.e(TAG, "forward: emitting");
}
}
public void reverse(View v){
if(!reverse.isChecked()){
_toneGenerator.stopTone();
Log.e(TAG, "reverse: not emitting");
}
else{
_toneGenerator.startTone(TONE_DTMF_1);
Log.e(TAG, "reverse: emitting");
}
}
public void c_clockwise(View v){
if(!c_clockwise.isChecked()){
_toneGenerator.stopTone();
Log.e(TAG, "c_clockwise: not emitting");
}
else{
_toneGenerator.startTone(TONE_DTMF_2);
Log.e(TAG, "c_clockwise: emitting");
}
}
public void clockwise(View v){
if(!clockwise.isChecked()){
_toneGenerator.stopTone();
Log.e(TAG, "clockwise: not emitting");
}
else{
_toneGenerator.startTone(TONE_DTMF_3);
Log.e(TAG, "clockwise: emitting");
}
}
public void pointTurnLeft(View v){
if(!pointTurnLeft.isChecked()){
_toneGenerator.stopTone();
Log.e(TAG, "pointTurnLeft: not emitting");
}
else{
_toneGenerator.startTone(TONE_DTMF_4);
Log.e(TAG, "pointTurnLeft: emitting");
}
}
public void pointTurnRight(View v){
if(!pointTurnRight.isChecked()){
_toneGenerator.stopTone();
Log.e(TAG, "pointTurnRight: not emitting");
}
else{
_toneGenerator.startTone(TONE_DTMF_5);
Log.e(TAG, "pointTurnRight: emitting");
}
}
}
你確定這將讓DTMF? – Layke 2012-10-24 16:27:08
是的,當它們連接到手機時,它將通過耳機播放DTMF音頻。我已經在DTMF控制的機器人中自己嘗試過了,一切正常。 – maciekb 2012-12-02 17:51:51