tratar el siguiente código ... se almacena para mí .....
@Override
public void onClick(View arg0) {
SQLiteDatabase myDb;
String MySQL;
byte[] byteImage1 = null;
byte[] byteImage2 = null;
MySQL="create table emp1(_id INTEGER primary key autoincrement, sample TEXT not null, picture BLOB);";
myDb = openOrCreateDatabase("Blob List", Context.MODE_PRIVATE, null);
myDb.execSQL(MySQL);
String s=myDb.getPath();
textView.append("\r\n" + s+"\r\n");
myDb.execSQL("delete from emp1");
ContentValues newValues = new ContentValues();
newValues.put("sample", "HI Hello");
try
{
FileInputStream instream = new FileInputStream("/sdcard/AudioRecorder/AudioRecorder.wav");
BufferedInputStream bif = new BufferedInputStream(instream);
byteImage1 = new byte[bif.available()];
bif.read(byteImage1);
textView.append("\r\n" + byteImage1.length+"\r\n");
newValues.put("picture", byteImage1);
long ret = myDb.insert("emp1", null, newValues);
if(ret<0) textView.append("\r\n!!! Error add blob filed!!!\r\n");
} catch (IOException e)
{
textView.append("\r\n!!! Error: " + e+"!!!\r\n");
}
Cursor cur = myDb.query("emp1",null, null, null, null, null, null);
cur.moveToFirst();
while (cur.isAfterLast() == false)
{
textView.append("\r\n" + cur.getString(1)+"\r\n");
cur.moveToNext();
}
///////Read data from blob field////////////////////
cur.moveToFirst();
byteImage2=cur.getBlob(cur.getColumnIndex("picture"));
bmImage.setImageBitmap(BitmapFactory.decodeByteArray(byteImage2, 0, byteImage2.length));
textView.append("\r\n" + byteImage2.length+"\r\n");
cur.close();
myDb.close();
}
});
Hola Ricardo, gracias por tu respuesta. Si almaceno mis archivos en la carpeta de activos, entonces mi tamaño de aplicación aumenta, ¿es esa la solución factible? por favor comenta sobre esto. o hay alguna forma de almacenar el archivo de audio en un formato de bajo consumo? –
Si almacena sus archivos en su base de datos, el tamaño de su aplicación también aumentará, no veo cómo podría hacerlo sin incluir más bytes sin aumentar el tamaño ... Podría intentar comprimirlos pero no ganaría mucho ya que los archivos de música ya están muy comprimidos ... –
@ Vinayak-Bevinakatti, si está preocupado por el tamaño del APK, puede ser que pueda descargar esos archivos de un servidor cuando su aplicación se ejecute por primera vez. – Rajeev