3

我刚开始开发,通过将图像转换为字节数组并将其存储到BLOB中的SQLite数据库(查找下面的代码),将图像成功存储到数据库。但我没有得到如何将音频的/视频的存储到数据库的任何一个可以帮助我PLZ ...如何在Android中将音频/视频文件存储到SQLite数据库?

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(); 
} 

在上面的代码是从SD卡拍摄图像和ImageView的显示和存储到数据库中。

回答

2

将媒体文件存储在内部/外部存储中,并将其路径存储在数据库中。

请参阅Saving Files

+0

请不要张贴链接作为答案。将来链接可能会改变,这将使这个答案无用。 –

+0

你说得对,但我真的不能做得更好。我所能做的就是压制这个声音 –

+0

Renaud感谢您的重播,您可以通过发送任何示例代码来帮助我... –

相关问题