public class PlayRecord extends CordovaPlugin {
@SuppressWarnings("resource")
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("playRecord")) {
String base64Code = (String) args.get(0);
int aa = base64Code.indexOf(",");
byte[] bufferByte = Base64.decode(base64Code.substring(aa+1), Base64.DEFAULT) ;
String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "//aaaaaaaa.amr";
try {
File file = new File(filePath);
file.delete();
if(!file.exists()){
file.createNewFile();
}
FileOutputStream fos;
fos = new FileOutputStream(file);
fos.write(bufferByte,0,bufferByte.length);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
CordovaActivity.handler.obtainMessage(2).sendToTarget();
return true;
}
return false;
}
}
@SuppressWarnings("resource")
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("playRecord")) {
String base64Code = (String) args.get(0);
int aa = base64Code.indexOf(",");
byte[] bufferByte = Base64.decode(base64Code.substring(aa+1), Base64.DEFAULT) ;
String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "//aaaaaaaa.amr";
try {
File file = new File(filePath);
file.delete();
if(!file.exists()){
file.createNewFile();
}
FileOutputStream fos;
fos = new FileOutputStream(file);
fos.write(bufferByte,0,bufferByte.length);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
CordovaActivity.handler.obtainMessage(2).sendToTarget();
return true;
}
return false;
}
}