何らかの理由で、ユーザーが3gデータを使用しているときにダウンロードボタンをクリックするたびに、画面が完全に真っ暗になり、アプリが強制終了を要求します。
private final String PATH = Environment.getExternalStorageDirectory() + "/folder";
public void DownloadFromUrl(String fileName, String saveTo) {
try {
URL url = new URL("http://example.com/" + fileName + ".png");
File file = new File(fileName + ".png");
long startTime = System.currentTimeMillis();
URLConnection urlconnection = url.openConnection();
InputStream iS = urlconnection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(iS);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
FileOutputStream fos = new FileOutputStream(PATH + saveTo);
fos.write(baf.toByteArray());
fos.close();
Toast t= Toast.makeText(getApplicationContext(), "Downloaded '" + saveTo + "' to '" + PATH + "'.", Toast.LENGTH_SHORT);
t.show();
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
}