Example usage for android.os Environment getDownloadCacheDirectory

List of usage examples for android.os Environment getDownloadCacheDirectory

Introduction

In this page you can find the example usage for android.os Environment getDownloadCacheDirectory.

Prototype

public static File getDownloadCacheDirectory() 

Source Link

Document

Return the download/cache content directory.

Usage

From source file:Main.java

public static File getSDCardDownloadCacheFile() {
    if (isSDCardEnable()) {
        return Environment.getDownloadCacheDirectory();
    } else {//from w  ww.  j  a  v a 2 s  . co  m
        return null;
    }
}

From source file:Main.java

public static String getSDPath() {
    if (checkSDCardAvailabel()) {
        return Environment.getExternalStorageDirectory().getPath();
    } else {/*w  w  w  .  jav a  2  s  .  c  o m*/
        return Environment.getDownloadCacheDirectory().getPath();
    }

}

From source file:Main.java

public static String getSDPath() {
    boolean hasSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    if (hasSDCard) {
        return Environment.getExternalStorageDirectory().toString();
    } else//w  w  w  .j  a  v  a 2 s.  c om
        return Environment.getDownloadCacheDirectory().toString();
}

From source file:Main.java

/**
 * @return the root of the filesystem containing the given path
 *///from w w  w  .j a  v a  2 s. com
public static File getFilesystemRoot(String path) {
    File cache = Environment.getDownloadCacheDirectory();
    if (path.startsWith(cache.getPath())) {
        return cache;
    }
    File external = Environment.getExternalStorageDirectory();
    if (path.startsWith(external.getPath())) {
        return external;
    }
    throw new IllegalArgumentException("Cannot determine filesystem root for " + path);
}

From source file:Main.java

/**
 * Checks whether the filename looks legitimate
 *///from   w  w w .  java  2 s  .  c  om
public static boolean isFilenameValid(String filename) {
    filename = filename.replaceFirst("/+", "/"); // normalize leading
    // slashes
    return filename.startsWith(Environment.getDownloadCacheDirectory().toString())
            || filename.startsWith(Environment.getExternalStorageDirectory().toString());
}

From source file:Main.java

/**
 * Checks whether the filename looks legitimate
 *//*from   ww w  .ja  va  2s.c om*/
static boolean isFilenameValid(String filename, File downloadsDataDir) {
    filename = filename.replaceFirst("/+", "/"); // normalize leading slashes
    return filename.startsWith(Environment.getDownloadCacheDirectory().toString())
            || filename.startsWith(downloadsDataDir.toString())
            || filename.startsWith(Environment.getExternalStorageDirectory().toString());
}

From source file:Main.java

/**
 * Checks whether the filename looks legitimate
 *//*from w  w w .  j a va2s  . co  m*/
static boolean isFilenameValid(String filename, File downloadsDataDir) {
    final String[] whitelist;
    try {
        filename = new File(filename).getCanonicalPath();
        whitelist = new String[] { downloadsDataDir.getCanonicalPath(),
                Environment.getDownloadCacheDirectory().getCanonicalPath(),
                Environment.getExternalStorageDirectory().getCanonicalPath(), };
    } catch (IOException e) {
        Log.w(TAG, "Failed to resolve canonical path: " + e);
        return false;
    }

    for (String test : whitelist) {
        if (filename.startsWith(test)) {
            return true;
        }
    }

    return false;
}

From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java

private Bitmap getIconBitmap(Context context, String iconUrl) {
    try {//from   ww  w  . j av a 2s . c om
        URL uRL = new URL(iconUrl);
        HttpURLConnection connection = (HttpURLConnection) uRL.openConnection();
        String cookie = CookieManager.getInstance().getCookie(iconUrl);
        if (null != cookie) {
            connection.setRequestProperty(SM.COOKIE, cookie);
        }
        connection.connect();
        if (200 == connection.getResponseCode()) {
            InputStream input = connection.getInputStream();
            if (input != null) {
                Environment.getDownloadCacheDirectory();
                File ecd = context.getExternalCacheDir();
                File file = new File(ecd, "pushIcon.png");
                OutputStream outStream = new FileOutputStream(file);
                byte buf[] = new byte[8 * 1024];
                while (true) {
                    int numread = input.read(buf);
                    if (numread == -1) {
                        break;
                    }
                    outStream.write(buf, 0, numread);
                }
                Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
                return bitmap;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.mozilla.gecko.GeckoAppShell.java

public static boolean loadLibsSetup(String apkName) {
    // The package data lib directory isn't placed in ld.so's
    // search path, so we have to manually load libraries that
    // libxul will depend on.  Not ideal.
    GeckoApp geckoApp = GeckoApp.mAppContext;
    GeckoProfile profile = geckoApp.getProfile();
    profile.moveProfilesToAppInstallLocation();

    try {/*  ww  w.j  a va2s. c o  m*/
        String[] dirs = GeckoApp.mAppContext.getPluginDirectories();
        StringBuffer pluginSearchPath = new StringBuffer();
        for (int i = 0; i < dirs.length; i++) {
            Log.i(LOGTAG, "dir: " + dirs[i]);
            pluginSearchPath.append(dirs[i]);
            pluginSearchPath.append(":");
        }
        GeckoAppShell.putenv("MOZ_PLUGIN_PATH=" + pluginSearchPath);
    } catch (Exception ex) {
        Log.i(LOGTAG, "exception getting plugin dirs", ex);
    }

    GeckoAppShell.putenv("HOME=" + profile.getFilesDir().getPath());
    GeckoAppShell.putenv("GRE_HOME=" + GeckoApp.sGREDir.getPath());
    Intent i = geckoApp.getIntent();
    String env = i.getStringExtra("env0");
    Log.i(LOGTAG, "env0: " + env);
    for (int c = 1; env != null; c++) {
        GeckoAppShell.putenv(env);
        env = i.getStringExtra("env" + c);
        Log.i(LOGTAG, "env" + c + ": " + env);
    }

    File f = geckoApp.getDir("tmp", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);

    if (!f.exists())
        f.mkdirs();

    GeckoAppShell.putenv("TMPDIR=" + f.getPath());

    f = Environment.getDownloadCacheDirectory();
    GeckoAppShell.putenv("EXTERNAL_STORAGE=" + f.getPath());

    File cacheFile = getCacheDir();
    String linkerCache = System.getenv("MOZ_LINKER_CACHE");
    if (System.getenv("MOZ_LINKER_CACHE") == null) {
        GeckoAppShell.putenv("MOZ_LINKER_CACHE=" + cacheFile.getPath());
    }

    File pluginDataDir = GeckoApp.mAppContext.getDir("plugins", 0);
    GeckoAppShell.putenv("ANDROID_PLUGIN_DATADIR=" + pluginDataDir.getPath());

    // gingerbread introduces File.getUsableSpace(). We should use that.
    long freeSpace = getFreeSpace();
    try {
        File downloadDir = null;
        File updatesDir = null;
        if (Build.VERSION.SDK_INT >= 8) {
            downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
            updatesDir = GeckoApp.mAppContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
        } else {
            updatesDir = downloadDir = new File(Environment.getExternalStorageDirectory().getPath(),
                    "download");
        }
        GeckoAppShell.putenv("DOWNLOADS_DIRECTORY=" + downloadDir.getPath());
        GeckoAppShell.putenv("UPDATES_DIRECTORY=" + updatesDir.getPath());
    } catch (Exception e) {
        Log.i(LOGTAG, "No download directory has been found: " + e);
    }

    putLocaleEnv();

    boolean extractLibs = GeckoApp.ACTION_DEBUG.equals(i.getAction());
    if (!extractLibs) {
        // remove any previously extracted libs
        File[] files = cacheFile.listFiles();
        if (files != null) {
            Iterator<File> cacheFiles = Arrays.asList(files).iterator();
            while (cacheFiles.hasNext()) {
                File libFile = cacheFiles.next();
                if (libFile.getName().endsWith(".so"))
                    libFile.delete();
            }
        }
    }
    return extractLibs;
}

From source file:com.bbxiaoqu.api.util.Utils.java

public static void clearCache(Context context) {
    File file = Environment.getDownloadCacheDirectory();
    File[] files = file.listFiles();
    if (files != null) {
        for (File f : files) {
            f.delete();//from w w  w.  j a v a2  s .  c o m
        }
    }
    file = context.getCacheDir();
    files = file.listFiles();
    if (files != null) {
        for (File f : files) {
            f.delete();
        }
    }
}