我正在尝试使用webView从文件主机(如zippyshare.com)下载文件.问题是,我不能使用意图来打开浏览器,或者通过DownloadManager重新路由它,因为它是基于会话/ cookie的,并且启动这些方法会将zip文件重定向到原始的html文件中以重新下载.
我试过了:
Uri source = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(source);
String cookie = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("Set-Cookie", cookie);
request.addRequestHeader("User-Agent", view.getSettings().getUserAgentString());
request.addRequestHeader("Accept", "text/html, application/xhtml+xml, *" + "/" + "*");
request.addRequestHeader("Accept-Language", "en-US,en;q=0.7,he;q=0.3");
request.addRequestHeader("Referer", url);
// Use the same file name for the destination
final File destinationDir = new File (Environment.getExternalStorageDirectory(), cordova.getActivity().getPackageName());
if (!destinationDir.exists()) {
destinationDir.mkdir(); // Don't forget to make the directory if it's not there
}
File destinationFile = new File (destinationDir, source.getLastPathSegment());
Log.e("FILEPOSITION", Uri.fromFile(destinationFile).toString());
request.setDestinationUri(Uri.fromFile(destinationFile));
// Add it to the …Run Code Online (Sandbox Code Playgroud) 我想用Cordova检测实时设备旋转(而不是方向,以度为单位旋转)。我使用了设备运动,但是得到了一堆加速度xy和z值,如何从中计算出旋转呢?
我想检测一个完整的360度旋转(想象将设备放在棍子或摆锤上,然后敲打使其摆动)。
谢谢!