我们正在使用多线程构建Android应用程序,因为它可以处理除MI以外的几乎所有设备以及其他一些不支持多线程的设备。
尝试使用新线程在后台调用录制服务。为此,我们创建了stopRecording()函数,它将调用新线程并在所有设备中正常工作,但只有少数像MI这样的设备无法工作,因为我们假设这些设备中没有多线程支持?
我们正在使用以下代码
if(TelephonyManager.EXTRA_STATE_IDLE.equals(state)&&recording==true)
{
//Toast.makeText(getApplicationContext(), state, Toast.LENGTH_LONG).show();
//Toast.makeText(arg0, "STOP Called :"+recording, Toast.LENGTH_LONG).show();
stopRecording();
}
public void stopRecording()
{
if(recording==true)
{
try
{
te = getCurrentTS();
recorder.stop();
recorder.reset();
recorder.release();
recorder=null;
recording=false;
editor.putString("mdialerRecording", "false");editor.commit();
//broadcastIntent();
//Toast.makeText(getApplicationContext(), "Recorder_Relesed", Toast.LENGTH_LONG).show();
File oldfile = new File(fname);
byte[] fileData = new byte[(int) oldfile.length()];
DataInputStream dis = new DataInputStream(new FileInputStream(oldfile));
dis.readFully(fileData);
dis.close();
oldfile.delete();
try
{
String s64mp3file=Base64.encodeToString(fileData,Base64.NO_WRAP);
String newKey=calledCRM+"_"+sysNumber+"_"+ts+"_"+te;
editor.putString(newKey, s64mp3file);
String mdialerKeys=settings.getString("mdialerKeys", "");
editor.putString("mdialerKeys", mdialerKeys+"|"+newKey);
editor.commit();
}
catch(Exception e)
{
//Toast.makeText(getApplicationContext(), "File_EX "+e.toString(), Toast.LENGTH_LONG).show();
}
calledCRM="";
if(calledNum.equals(sysNumber))deleteLogNumber(sysNumber);
calledNum="";
}
catch(Exception e)
{
//Toast.makeText(getApplicationContext(), "Rec_Stop_EX "+e.toString(), Toast.LENGTH_LONG).show();
}
}
}