本文整理汇总了Java中com.kinvey.java.core.MediaHttpDownloader类的典型用法代码示例。如果您正苦于以下问题:Java MediaHttpDownloader类的具体用法?Java MediaHttpDownloader怎么用?Java MediaHttpDownloader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaHttpDownloader类属于com.kinvey.java.core包,在下文中一共展示了MediaHttpDownloader类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: download
import com.kinvey.java.core.MediaHttpDownloader; //导入依赖的package包/类
private void download(File target) throws IOException {
FileOutputStream fos= new FileOutputStream(target);
// call kinvey specific task to perform download
FileMetaData meta = new FileMetaData(FileActivity.FILENAME);
meta.setId(FileActivity.FILENAME);
getApplicationContext().getClient().file().downloadWithTTL(meta.getId(), 1200000, fos, new DownloaderProgressListener() {
@Override
public void progressChanged(MediaHttpDownloader downloader) throws IOException {
Log.i(KitchenSink.TAG, "progress updated: "+downloader.getDownloadState());
final String state = new String(downloader.getDownloadState().toString());
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
tProgress.setText((tProgress.getText() == null) ? state
: tProgress.getText() + "\n" + state);
}
});
}
@Override
public void onSuccess(Void result) {
Log.i(KitchenSink.TAG, "successfully download: " + getTarget().getName() + " file.");
Toast.makeText(getActivity(), "Download finished.", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Throwable error) {
Log.e(KitchenSink.TAG, "failed to download: "+ getTarget().getName()+" file.", error);
Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_LONG).show();
}
});
}