ASTRO에서 액세스 할 수있는 Android에 mp3를 저장하는 프로그램을 만들려고합니다. 파일을/sdcard/media/audio에 저장하려고합니다. Logcat/DDMS에 대한 단일 오류없이 진행되는 응용 프로그램에도 불구하고 파일을 찾을 수 없습니다. WRITE_EXTERNAL_STORAGE 권한 (인터넷 등과 함께)을 추가하여 그렇게하지 않았습니다.Android : 파일을 sdcard에 저장 하시겠습니까?
앱이 sdcard에 파일을 저장하는 데 제한이 있습니까? 라는
방법 :
public void findSong(View view) throws Exception {
edittext = (EditText) findViewById(R.id.edittext);
searchTerm = edittext.getText().toString();
String address;
address = getMusic(searchTerm);
ImageManager img = new ImageManager(); //calls ImageManager (below)
img.DownloadFromUrl(address, title + ".mp3");
}
다운로드 방법 : 어떤 도움을 주시면 감사
private final String PATH = "/data/data"; //put the downloaded file here
public void DownloadFromUrl(String imageURL, String fileName) {
//this is the downloader method
try {
URL url = new URL(imageURL); //you can write here any link
File file = new File(fileName);
long startTime = System.currentTimeMillis();
Log.d("ImageManager", "download begining");
Log.d("ImageManager", "download url:" + url);
Log.d("ImageManager", "downloaded file name:" + fileName);
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
/* Define InputStreams to read from the URLConnection. */
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
/* Read bytes to the Buffer until there is nothing more to read(-1). */
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
FileOutputStream fos = new FileOutputStream(PATH + file);
fos.write(baf.toByteArray());
fos.close();
Log.d("ImageManager", "download ready in"
+ ((System.currentTimeMillis() - startTime)/1000)
+ " sec");
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
}
.
onCreate()에서 다운로드 할 필요가없는 정적 콘텐츠가 포함 된 더미 텍스트 파일을 작성하는 것과 같은 간단한 작업을 시도해보십시오. 일반적으로 좋은 생각은 아니지만 몇 가지 코드 만 사용하면됩니다. 파일을 쓰는 방법을 알아 냈는지 확인하십시오. –
당신의 코드가 '/ data/data'에 파일을 넣고있는 것을 보여 주지만 질문에 '/ sdcard/media/audio'라고 쓰여 있습니다. – Squonk