2013-02-04 61 views

回答

1

首先確保你的應用程序有適當的權限,包括android.permission.WRITE_EXTERNAL_STORAGE

然後你就可以複製從您的資源到Android設備的文件。下面是說明目的只有一個示例代碼,更改需要:

private void copyMp3() throws IOException{ 

// Open your mp3 file as the input stream 
InputStream myInput = getAssets().open("your_file.mp3"); 

// Path to the output file on the device 
String outFileName = new File(Environment.getExternalStoragePublicDirectory(
     Environment.DIRECTORY_MUSIC),"your_file.mp3"); 

OutputStream myOutput = new FileOutputStream(outFileName); 

//transfer bytes from the inputfile to the outputfile 
byte[] buffer = new byte[1024]; 
int length; 
while ((length = myInput.read(buffer))>0){ 
    myOutput.write(buffer, 0, length); 
} 

//Close the streams => Better to have it in *final* block 
myOutput.flush(); 
myOutput.close(); 
myInput.close(); 

} 

媒體掃描儀應該由自己挑選的文件(除非該文件夾中的文件.nomedia),但如果你想加快進程速度,您可以使用您在問題中提到的鏈接。