小编Luk*_*ing的帖子

getExternalStorageDirectory无效

我正在尝试将文件保存到运行4.2.2的Samsung Galaxy Nexus上的SD卡.从我的应用程序我正在使用

Environment.getExternalStorageDirectory()
Run Code Online (Sandbox Code Playgroud)

但它回来了

/storage/emulated/0/
Run Code Online (Sandbox Code Playgroud)

这不是我的SD卡信息所在的位置.我可以使用任何工作方法来获取SD卡的正确路径吗?

java android sd-card

44
推荐指数
3
解决办法
4万
查看次数

在jellybean中出现NetworkOnMainThreadException错误

我一直试图在上周左右开始工作,但仍然不知道问题是什么.它适用于Android 2.1但不适用于4.1.我已经在服务中找到了这个字符串,检查我的应用程序中的更新.

latestVersion = Integer.parseInt(getHttpString(urlLatestVersion));
Run Code Online (Sandbox Code Playgroud)

它在checkForUpdate()中调用; 在onStart中调用(Intent intent,int startId);.

private String getHttpString(String urlString) throws IOException {
            InputStream in = null;
            int response = -1;

            URL url = new URL(urlString);
            URLConnection conn = url.openConnection();

            if (!(conn instanceof HttpURLConnection))
                    throw new IOException("Not an HTTP connection");

            try {
                    HttpURLConnection httpConn = (HttpURLConnection) conn;
                    httpConn.setAllowUserInteraction(false);
                    httpConn.setInstanceFollowRedirects(true);
                    httpConn.setRequestMethod("GET");
                    httpConn.connect();

                    response = httpConn.getResponseCode();
                    if (response == HttpURLConnection.HTTP_OK) {
                            in = httpConn.getInputStream();
                    }
            } catch (Exception ex) {
                    ex.printStackTrace();
                    //
                    //main error currently lies here
                    // TODO …
Run Code Online (Sandbox Code Playgroud)

android onstart httpurlconnection android-asynctask networkonmainthread

8
推荐指数
1
解决办法
7518
查看次数

覆盖服务器上的文件(PHP)

我正在制作一个Android应用程序,需要能够将文件推送到服务器上.

为此,我正在使用POST,fopen/fwrite但此方法仅附加到文件并unlink在写入文件之前使用无效.(file_put_contents具有完全相同的效果)

这就是我到目前为止所拥有的

<?php
$fileContent = $_POST['filecontent'];

$relativePath = "/DatabaseFiles/SavedToDoLists/".$_POST['filename'];
$savePath = $_SERVER["DOCUMENT_ROOT"].$relativePath; 

unlink($savePath);

$file = fopen($savePath,"w");
fwrite($file,$fileContent);
fclose($file);

?>
Run Code Online (Sandbox Code Playgroud)

当我不尝试写入文件时,该文件将正确删除它自己,但如果我尝试写入它,它将附加.

有人有任何关于覆盖文件内容的建议吗?

谢谢,卢克.

php fopen overwrite fwrite unlink

6
推荐指数
2
解决办法
2万
查看次数

使用javascript获取元素的子元素

我如何使用Javascript,而不是jQuery,来获取某个元素内的所有图像.我也需要通过标签来获取它们.

我也正在寻找受影响的图像

#container img
Run Code Online (Sandbox Code Playgroud)

#container > img
Run Code Online (Sandbox Code Playgroud)

谢谢,卢克:).

javascript image

5
推荐指数
1
解决办法
6635
查看次数