本文整理汇总了Java中com.google.android.vending.expansion.downloader.Helpers.isExternalMediaMounted方法的典型用法代码示例。如果您正苦于以下问题:Java Helpers.isExternalMediaMounted方法的具体用法?Java Helpers.isExternalMediaMounted怎么用?Java Helpers.isExternalMediaMounted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.vending.expansion.downloader.Helpers
的用法示例。
在下文中一共展示了Helpers.isExternalMediaMounted方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateSaveFile
import com.google.android.vending.expansion.downloader.Helpers; //导入方法依赖的package包/类
/**
* Creates a filename (where the file should be saved) from info about a
* download.
*/
public String generateSaveFile(String filename, long filesize)
throws GenerateSaveFileError {
String path = generateTempSaveFileName(filename);
File expPath = new File(path);
if (!Helpers.isExternalMediaMounted()) {
Log.d(Constants.TAG, "External media not mounted: " + path);
throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR,
"external media is not yet mounted");
}
if (expPath.exists()) {
Log.d(Constants.TAG, "File already exists: " + path);
throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR,
"requested destination file already exists");
}
if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) {
throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR,
"insufficient space on external storage");
}
return path;
}
示例2: writeDataToDestination
import com.google.android.vending.expansion.downloader.Helpers; //导入方法依赖的package包/类
/**
* Write a data buffer to the destination file.
*
* @param data buffer containing the data to write
* @param bytesRead how many bytes to write from the buffer
*/
private void writeDataToDestination(State state, byte[] data, int bytesRead)
throws StopRequest {
for (;;) {
try {
if (state.mStream == null) {
state.mStream = new FileOutputStream(state.mFilename, true);
}
state.mStream.write(data, 0, bytesRead);
// we close after every write --- this may be too inefficient
closeDestination(state);
return;
} catch (IOException ex) {
if (!Helpers.isExternalMediaMounted()) {
throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
"external media not mounted while writing destination file");
}
long availableBytes =
Helpers.getAvailableBytes(Helpers.getFilesystemRoot(state.mFilename));
if (availableBytes < bytesRead) {
throw new StopRequest(DownloaderService.STATUS_INSUFFICIENT_SPACE_ERROR,
"insufficient space while writing destination file", ex);
}
throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
"while writing destination file: " + ex.toString(), ex);
}
}
}
示例3: writeDataToDestination
import com.google.android.vending.expansion.downloader.Helpers; //导入方法依赖的package包/类
/**
* Write a data buffer to the destination file.
*
* @param data buffer containing the data to write
* @param bytesRead how many bytes to write from the buffer
*/
private void writeDataToDestination(State state, byte[] data, int bytesRead)
throws StopRequest {
for (;;) {
try {
if (state.mStream == null) {
state.mStream = new FileOutputStream(state.mFilename, true);
}
state.mStream.write(data, 0, bytesRead);
// we close after every write --- this may be too inefficient
closeDestination(state);
return;
} catch (IOException ex) {
if (!Helpers.isExternalMediaMounted()) {
throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
"external media not mounted while writing destination file");
}
long availableBytes =
Helpers.getAvailableBytes(Helpers.getFilesystemRoot(state.mFilename));
if (availableBytes < bytesRead) {
throw new StopRequest(DownloaderService.STATUS_INSUFFICIENT_SPACE_ERROR,
"insufficient space while writing destination file", ex);
}
throw new StopRequest(DownloaderService.STATUS_FILE_ERROR,
"while writing destination file: " + ex.toString(), ex);
}
}
}