Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store the audio/Video file to SQLite database in android.? [duplicate]

Am new to developing, am successfully store the images to database by converting the images in to bytes array and store it to SQLite database in BLOB (find below code). But am not getting how to store audio's/video's into DB any one help me PLZ...

 public void getImage(View view){
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.setType("image/* video/*");
    startActivityForResult(Intent.createChooser(intent, "select picture"), 1);

}

public void onActivityResult(int requestCode, int resultCode, Intent data){
    if(resultCode == RESULT_OK){
        Uri imageUri = data.getData();
        String imagePath = getPath(imageUri);

        image1.setVisibility(View.VISIBLE);

        image1.setImageURI(imageUri);
        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
        Toast.makeText(getApplicationContext(), ""+bitmap, Toast.LENGTH_SHORT).show();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
        img = byteArrayOutputStream.toByteArray();
    }
}

 public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

public void saveImage(View v){

    imageDatabase = new ImageDatabase(this);

    imageDatabase.insert("first",img);

    Toast.makeText(getApplicationContext(), ""+imageDatabase.numberOfRows(),Toast.LENGTH_LONG).show();
}

In above code am taking the image from sdcard and displaying in ImageView and storing into DB.

like image 475
chethankumar Avatar asked Jan 15 '16 11:01

chethankumar


1 Answers

Store the media files in internal/external storage, and store the path to it in your database.

see Saving Files

like image 104
Renaud Favier Avatar answered Sep 20 '22 23:09

Renaud Favier