package com.avcon.mic;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.sql.Connection;
import java.util.Vector;
import com.avcon.mic.AudioTool.MicRealTimeListener;
import com.avcon.mic.AudioTool.MicrophoneThread;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MicDemoActivity extends Activity implements OnClickListener{
private TextView tView1,tView2;
private Button button1,button2,button3,button4;
private MHandler mHandler;
private MediaRecorder mARecorder;
private File mAudiofile,mSampleDir;
private MicrophoneThread microphone;
//private RecordThread recordThread;
private boolean istrue = true;
private static final String CONSER = "logInfo:";
private Runtime runtime = null;
private Process process = null;//服务器连接进程
private DataInputStream logInfoStream = null;
public StringBuffer stateInfoParser = null;
Process localProcess ;
class MHandler extends Handler{
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case 1:
tView1.setText( msg.obj.toString());
break;
case 2:
tView2.setText("///////////////"+msg.obj.toString());
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
mHandler = new MHandler();
microphone = new MicrophoneThread();
// recordThread = new RecordThread();
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
button4.setOnClickListener(this);
}
private void init(){
tView1 = (TextView) findViewById(R.id.textView1);
tView2 = (TextView) findViewById(R.id.textView2);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
}
@Override
public void onClick(View v) {
// 在代码中运行linux命令
switch (v.getId()) {
case R.id.button1:
Log.v("ClientField.LOG_TAG "," LogTagField.THREAD_CON "+ "进入连接线程!");
runtime = Runtime.getRuntime();
try
{
process = runtime.exec("ls /system/bin/");
if (process != null)
{
try
{
Object localObject = process.getOutputStream();
Object intputObject = process.getInputStream();
Object errorObject = process.getErrorStream();
DataOutputStream localDataOutputStream = new DataOutputStream((OutputStream)localObject);
localDataOutputStream.flush();
Log.v("ClientField.LOG_TAG" ,"LogTagField.THREAD_CON" + "执行连接命令");
logInfoStream = new DataInputStream((InputStream)intputObject);
DataInputStream erroStream = new DataInputStream((InputStream) errorObject);
String lineInfo = "";
stateInfoParser = new StringBuffer();
while ((lineInfo = logInfoStream.readLine()) != null)
{
stateInfoParser.append(lineInfo);
stateInfoParser.append("\n");
Log.v("MicDemoActivity" , "stateInfoParser.append ls "+ stateInfoParser.toString());
}
Log.v("MicDemoActivity" , "LogTagField.THREAD_CON "+ "跳出连接线程!");
String lineInfo1 = "";
// localDataOutputStream.writeBytes("/sdcard/ls /sdcard");
// localDataOutputStream.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
process = runtime.exec("ls");
if (process != null)
{
process.waitFor();
}
//tView1.setText(stateInfoParser.toString());
}else
{
Log.e("ClientField.LOG_TAG" ,"LogTagField.THREAD_CON" + "process is null");
}
}catch (Exception e) {
e.printStackTrace();
Log.e("ClientField.LOG_TAG "," LogTagField.THREAD_CON" + "runtim error");
process = null;
}
tView1.setText(stateInfoParser.toString());
break;
case R.id.button2:
Toast.makeText(MicDemoActivity.this, "录音结束", Toast.LENGTH_LONG).show();
button1.setEnabled(true);
mARecorder.stop();
istrue = false;
microphone.stop();
mARecorder.release();
mARecorder = null;
break;
// case R.id.button3:
/**跳转至本机安装的超级终端*/
// ComponentName componentName=new
// ComponentName("com.magicandroidapps.bettertermpro","com.magicandroidapps.bettertermpro.BetterTerm");
// Intent intent=new Intent();
// intent.setComponent(componentName);
// intent.setAction(Intent.ACTION_VIEW);
// startActivity(intent);
//
// break;
case R.id.button4:
Vector localVector = new Vector();
try
{
localProcess = Runtime.getRuntime().exec("su ");
Log.e("MicDemoActivity", "第一命令");
OutputStream localOutputStream = localProcess.getOutputStream();
DataOutputStream localDataOutputStream = new DataOutputStream(localOutputStream);
InputStream localInputStream = localProcess.getInputStream();
DataInputStream localDataInputStream = new DataInputStream(localInputStream);
String str1 = String.valueOf("ls");
String str2 = str1 + "\n";
localDataOutputStream.writeBytes(str2);
Log.e("MicDemoActivity", "第er命令");
localProcess = Runtime.getRuntime().exec(str2);
localOutputStream = localProcess.getOutputStream();
localInputStream = localProcess.getInputStream();
localDataInputStream = new DataInputStream(localInputStream);
System.out.println("111"+localDataInputStream.readLine());
localDataOutputStream.flush();
localDataOutputStream.writeBytes("exit");
Log.e("MicDemoActivity", "第三命令");
localOutputStream = localProcess.getOutputStream();
localInputStream = localProcess.getInputStream();
localDataInputStream = new DataInputStream(localInputStream);
System.out.println("222"+localDataInputStream.readLine());
localDataOutputStream.flush();
String str3 = localDataInputStream.readLine();
localVector.add(str3);
localProcess.waitFor();
// tView1.setText(localVector.toString());
}
catch (Exception localException)
{
localException.printStackTrace();
}
break;
}
}
@Override
protected void onStart() {
// 录音获取麦克风声音
super.onStart();
Toast.makeText(MicDemoActivity.this, "录音开始", Toast.LENGTH_LONG).show();
button1.setEnabled(false);
mARecorder = new MediaRecorder();
mARecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mARecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
mARecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mSampleDir = Environment.getExternalStorageDirectory();
mAudiofile = File.createTempFile(
- 1
- 2
- 3
- 4
- 5
- 6
前往页