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感謝您的重播,您可以通過發送任何示例代碼來幫助我... –

相關問題