Example usage for android.content Context getFilesDir

List of usage examples for android.content Context getFilesDir

Introduction

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

Prototype

public abstract File getFilesDir();

Source Link

Document

Returns the absolute path to the directory on the filesystem where files created with #openFileOutput are stored.

Usage

From source file:com.crte.sipstackhome.ui.preferences.PreferencesWrapper.java

public static File getZrtpFolder(Context ctxt) {
    return ctxt.getFilesDir();
    /*return getSubFolder(ctxt, ZRTP_FOLDER, true);*/
}

From source file:me.wcy.weather.utils.ACache.java

public static ACache get(Context ctx, String cacheName) {
    File f = new File(ctx.getFilesDir(), cacheName);
    return get(f, MAX_SIZE, MAX_COUNT);
}

From source file:com.netdoers.com.stacktrace.ExceptionHandler.java

/**
 * Register handler for unhandled exceptions.
 * @param context/*from   w  ww . j a v a  2s . c o  m*/
 */
public static boolean register(Context context) {
    Log.i(TAG, "Registering default exceptions handler");
    // Get information about the Package
    PackageManager pm = context.getPackageManager();
    try {
        PackageInfo pi;
        // Version
        pi = pm.getPackageInfo(context.getPackageName(), 0);
        G.APP_VERSION = pi.versionName;
        // Version Code name
        G.APP_VERSION_CODE = String.valueOf(pi.versionCode);//ADDED VERSION CODE
        // Package name
        G.APP_PACKAGE = pi.packageName;
        // Files dir for storing the stack traces
        G.FILES_PATH = context.getFilesDir().getAbsolutePath();
        // Device model
        G.PHONE_MODEL = android.os.Build.MODEL;
        // Device Size
        G.PHONE_SIZE = SmartConsultant.getPreferences().getDeviceSize();
        // Android version
        G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    Log.i(TAG, "TRACE_VERSION: " + G.TraceVersion);
    Log.d(TAG, "APP_VERSION: " + G.APP_VERSION);
    Log.d(TAG, "APP_VERSION_CODE: " + G.APP_VERSION_CODE);//ADDED VERSION CODE
    Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE);
    Log.d(TAG, "FILES_PATH: " + G.FILES_PATH);
    Log.d(TAG, "URL: " + G.URL);

    boolean stackTracesFound = false;
    // We'll return true if any stack traces were found
    if (searchForStackTraces().length > 0) {
        stackTracesFound = true;
    }

    new Thread() {
        @Override
        public void run() {
            // First of all transmit any stack traces that may be lying around
            submitStackTraces();
            UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();
            if (currentHandler != null) {
                Log.d(TAG, "current handler class=" + currentHandler.getClass().getName());
            }
            // don't register again if already registered
            if (!(currentHandler instanceof DefaultExceptionHandler)) {
                // Register default exceptions handler
                Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(currentHandler));
            }
        }
    }.start();

    return stackTracesFound;
}

From source file:com.netdoers.zname.errorreporting.ExceptionHandler.java

/**
 * Register handler for unhandled exceptions.
 * @param context/*from w  ww.  j  a  v  a  2 s.  c  o  m*/
 */
public static boolean register(Context context) {
    Log.i(TAG, "Registering default exceptions handler");
    // Get information about the Package
    PackageManager pm = context.getPackageManager();
    try {
        PackageInfo pi;
        // Version
        pi = pm.getPackageInfo(context.getPackageName(), 0);
        G.APP_VERSION = pi.versionName;
        // Version Code name
        G.APP_VERSION_CODE = String.valueOf(pi.versionCode);//ADDED VERSION CODE
        // Package name
        G.APP_PACKAGE = pi.packageName;
        // Files dir for storing the stack traces
        G.FILES_PATH = context.getFilesDir().getAbsolutePath();
        // Device model
        G.PHONE_MODEL = android.os.Build.MODEL;
        // Device Size
        G.PHONE_SIZE = Zname.getPreferences().getDeviceSize();
        // Android version
        G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    Log.i(TAG, "TRACE_VERSION: " + G.TraceVersion);
    Log.d(TAG, "APP_VERSION: " + G.APP_VERSION);
    Log.d(TAG, "APP_VERSION_CODE: " + G.APP_VERSION_CODE);//ADDED VERSION CODE
    Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE);
    Log.d(TAG, "FILES_PATH: " + G.FILES_PATH);
    Log.d(TAG, "URL: " + G.URL);

    boolean stackTracesFound = false;
    // We'll return true if any stack traces were found
    if (searchForStackTraces().length > 0) {
        stackTracesFound = true;
    }

    new Thread() {
        @Override
        public void run() {
            // First of all transmit any stack traces that may be lying around
            submitStackTraces();
            UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();
            if (currentHandler != null) {
                Log.d(TAG, "current handler class=" + currentHandler.getClass().getName());
            }
            // don't register again if already registered
            if (!(currentHandler instanceof DefaultExceptionHandler)) {
                // Register default exceptions handler
                Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(currentHandler));
            }
        }
    }.start();

    return stackTracesFound;
}

From source file:me.wcy.weather.utils.ACache.java

public static ACache get(Context ctx, long max_zise, int max_count) {
    File f = new File(ctx.getFilesDir(), "ACache");
    return get(f, max_zise, max_count);
}

From source file:com.application.error.ExceptionHandler.java

/**
 * Register handler for unhandled exceptions.
 * @param context/*from w ww. j a  va  2s .  co  m*/
 */
public static boolean register(Context context) {
    Log.i(TAG, "Registering default exceptions handler");
    // Get information about the Package
    PackageManager pm = context.getPackageManager();
    try {
        PackageInfo pi;
        // Version
        pi = pm.getPackageInfo(context.getPackageName(), 0);
        G.APP_VERSION = pi.versionName;
        // Version Code name
        G.APP_VERSION_CODE = String.valueOf(pi.versionCode);//ADDED VERSION CODE
        // Package name
        G.APP_PACKAGE = pi.packageName;
        // Files dir for storing the stack traces
        G.FILES_PATH = context.getFilesDir().getAbsolutePath();
        // Device model
        G.PHONE_MODEL = android.os.Build.MODEL;
        // Device Size
        try {
            G.PHONE_SIZE = String.valueOf(Utilities.checkDisplaySize());
        } catch (Exception e) {
            G.PHONE_SIZE = "DEVICE SIZE NOT FOUND";
        }
        // Android version
        G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    Log.i(TAG, "TRACE_VERSION: " + G.TraceVersion);
    Log.d(TAG, "APP_VERSION: " + G.APP_VERSION);
    Log.d(TAG, "APP_VERSION_CODE: " + G.APP_VERSION_CODE);//ADDED VERSION CODE
    Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE);
    Log.d(TAG, "FILES_PATH: " + G.FILES_PATH);
    Log.d(TAG, "URL: " + G.URL);

    boolean stackTracesFound = false;
    // We'll return true if any stack traces were found
    if (searchForStackTraces().length > 0) {
        stackTracesFound = true;
    }

    new Thread() {
        @Override
        public void run() {
            // First of all transmit any stack traces that may be lying around
            submitStackTraces();
            UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();
            if (currentHandler != null) {
                Log.d(TAG, "current handler class=" + currentHandler.getClass().getName());
            }
            // don't register again if already registered
            if (!(currentHandler instanceof DefaultExceptionHandler)) {
                // Register default exceptions handler
                Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(currentHandler));
            }
        }
    }.start();

    return stackTracesFound;
}

From source file:Main.java

/**
 * Create a File for saving an image or video
 *//*from   w  w w  . j  a  v a 2  s  .co m*/
@SuppressLint("SimpleDateFormat")
public static File getOutputMediaFile(int type, Context context) {
    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile = null;
    if (type == MEDIA_TYPE_IMAGE) {
        File mediaStorageDir = new File(
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "StoryCapture");
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.d("StoryCapture", "failed to create directory");
                return null;
            }
        }
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
    } else if (type == MEDIA_TYPE_AUDIO) {
        String fileName = "AUDIO_" + timeStamp + ".3gp";
        mediaFile = new File(context.getFilesDir(), fileName);
    }
    return mediaFile;
}

From source file:com.syw.weiyu.util.ACache.java

/**
 * ??//from   ww w  .  j a  v  a 2s. co  m
 * ACache?cache
 * ?filesAFiles?
 * @return
 */
public static ACache getPermanence(Context ctx) {
    File f = new File(ctx.getFilesDir(), "AFiles");
    return get(f, MAX_SIZE, MAX_COUNT);
}

From source file:com.syw.weiyu.util.ACache.java

/**
 * ??/*from   w ww  . ja  v  a  2s . co  m*/
 * ACache?cache
 * ?files
 * @param permanenceName ???
 * @return
 */
public static ACache getPermanence(Context ctx, String permanenceName) {
    File f = new File(ctx.getFilesDir(), permanenceName);
    return get(f, MAX_SIZE, MAX_COUNT);
}

From source file:com.noshufou.android.su.util.Util.java

public static boolean writeDefaultStoreFile(Context context) {
    File storedDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + "stored");
    storedDir.mkdirs();/*from w  ww. ja  v a 2  s .c  o m*/
    File defFile = new File(storedDir.getAbsolutePath() + File.separator + "default");
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String action = prefs.getString(Preferences.AUTOMATIC_ACTION, "prompt");
    try {
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(defFile.getAbsolutePath()));
        out.write(action);
        out.write("\n");
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        Log.w(TAG, "Default file not written", e);
        return false;
    } catch (IOException e) {
        Log.w(TAG, "Default file not written", e);
        return false;
    }
    return true;
}