Example usage for android.content Context MODE_WORLD_READABLE

List of usage examples for android.content Context MODE_WORLD_READABLE

Introduction

In this page you can find the example usage for android.content Context MODE_WORLD_READABLE.

Prototype

int MODE_WORLD_READABLE

To view the source code for android.content Context MODE_WORLD_READABLE.

Click Source Link

Document

File creation mode: allow all other applications to have read access to the created file.

Usage

From source file:Main.java

public static boolean ReadSharedPreferencesBoolean(Context context, String name, String key,
        boolean defaultvalue) {
    try {/*from   w  ww .j av a 2  s  . c o  m*/
        SharedPreferences userInfo = context.getSharedPreferences(name, Context.MODE_WORLD_READABLE);
        return userInfo.getBoolean(key, defaultvalue);
    } catch (NullPointerException e) {
        return true;
    }
}

From source file:Main.java

private static boolean levelExist(int level) {
    if (mLevelSet == null)
        mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET,
                null);//from ww  w  .j a  v a 2 s. c o  m
    if (mLevelSet == null) {
        mLevelSet = new TreeSet<String>();
        mLevelSet.add(String.valueOf(level));
        mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_WRITEABLE).edit()
                .putStringSet(LEVELSET, mLevelSet).commit();
        return false;
    }
    if (mLevelSet.contains(String.valueOf(level)))
        return true;
    else {
        mLevelSet.add(String.valueOf(level));
        mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_WRITEABLE).edit()
                .putStringSet(LEVELSET, mLevelSet).commit();
    }
    return false;
}

From source file:Main.java

public static boolean saveScreenshot(Activity activity, String fileName, Bitmap screenshot, boolean sdcard) {
    try {//  w  w w .j  a  v  a 2s .c  o m
        FileOutputStream fos = null;
        if (!sdcard) {
            fos = activity.openFileOutput(fileName, Context.MODE_WORLD_READABLE);
        } else {
            File f = new File(fileName);
            f.createNewFile();
            fos = new FileOutputStream(f);
        }
        screenshot.compress(Bitmap.CompressFormat.JPEG, 70, fos);
        fos.flush();
        fos.close();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static boolean savePngScreenshot(Activity activity, String fileName, Bitmap screenshot, boolean sdcard) {
    try {//ww w  . j a  va  2 s. c  o  m
        FileOutputStream fos = null;
        if (!sdcard) {
            fos = activity.openFileOutput(fileName, Context.MODE_WORLD_READABLE);
        } else {
            File f = new File(fileName);
            f.createNewFile();
            fos = new FileOutputStream(f);
        }
        screenshot.compress(Bitmap.CompressFormat.PNG, 70, fos);
        fos.flush();
        fos.close();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

/**
 * Read a file, used for reading weather file from assets
 * @param fileName//from ww  w  .ja  v a2  s  . c  om
 * @param context
 * @return
 */
public static String readFromAssetsFile(String fileName, Context context) {
    StringBuilder returnString = new StringBuilder();
    InputStream fIn = null;
    InputStreamReader isr = null;
    BufferedReader input = null;
    try {
        fIn = context.getResources().getAssets().open(fileName, Context.MODE_WORLD_READABLE);
        isr = new InputStreamReader(fIn);
        input = new BufferedReader(isr);
        String line = "";
        while ((line = input.readLine()) != null) {
            returnString.append(line);
        }
    } catch (Exception e) {
    } finally {
        try {
            if (isr != null) {
                isr.close();
            }
            if (fIn != null) {
                fIn.close();
            }
            if (input != null) {
                input.close();
            }
        } catch (Exception e2) {
        }
    }
    return returnString.toString();
}

From source file:Main.java

public static boolean isLowestLevel(int level) {
    if (mLevelSet == null)
        mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET,
                null);/*from w  w w.j  a  va 2  s  . c o m*/
    if (mLevelSet != null) {
        if (mLevelSet.size() < 5) // data is too few to judge lowest
            return false;
        ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet));
        Collections.sort(array, mComparator);
        // TODO: may need check statistics to ensure the level is true lowest and not false alarm.
        if (level <= Integer.valueOf(array.get(0)))
            return true;
    }
    return false;
}

From source file:Main.java

public static String dumpLuxLevel() {
    String result = "";
    if (mLevelSet == null)
        mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET,
                null);//from  w  w w  .ja v a 2 s  .com
    if (mLevelSet != null) {
        ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet));
        Collections.sort(array, mComparator);
        result = array.toString();
    }
    return result;
}

From source file:Main.java

public static boolean getBoundaryLevel(Point bound) {
    if (mLevelSet == null)
        mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET,
                null);//from   w  w w.j a  va 2 s . c o  m
    if (mLevelSet != null) {
        ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet));
        Collections.sort(array, mComparator);
        bound.x = Integer.valueOf(array.get(0));
        bound.y = Integer.valueOf(array.get(array.size() - 1));
        return true;
    }
    return false;
}

From source file:Main.java

public static SharedPreferences getApplicationIconBadgeSettings(Context context) {
    return context.getSharedPreferences("notificationsiconbadge", Context.MODE_WORLD_READABLE);
}

From source file:Main.java

public static SharedPreferences getCommonPreferences(final Context context) {
    return context.getSharedPreferences(COMMON_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
}