我的应用程序的目标是检查是否有其他录制应用程序正在工作或者如果micriphone正忙/正在录制。这是代码:
私人MediaRecorder mRecord = null;
public void start() {
if (mRecord == null) {
mRecord = new MediaRecorder();
mRecord.setAudioSource(MediaRecorder.AudioSource.MIC);
try {
mRecord.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mRecord.start();
}
}
public void stop() {
if (mRecord != null) {
mRecord.stop();
mRecord.release();
mRecord = null;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnCheck = (Button) findViewById(R.id.btnCheck);
btnCheck.setOnClickListener(MainActivity.this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnCheck:
if (mRecord != null) {
mRecord.stop();
mRecord.release();
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View convertView = null;
alertDialog.setView(convertView);
alertDialog.setTitle("You are being recorded!!!");
alertDialog.show();
}
else {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View convertView = null;
alertDialog.setView(convertView);
alertDialog.setTitle("All clear");
alertDialog.show();
}
break;
如果另一个应用程序是recordind我没有得到消息"你正在被记录!!!" 有什么改进的想法吗?