List of usage examples for android.app Application getFilesDir
@Override
public File getFilesDir()
From source file:com.jeffthefate.stacktrace.ExceptionHandler.java
/** * Register handler for unhandled exceptions. * @param context/* w ww . j a va2 s . com*/ */ public static boolean register(Application app) { mCallback = (OnStacktraceListener) app; Log.i(TAG, "Registering default exceptions handler"); // Get information about the Package PackageManager pm = app.getPackageManager(); try { PackageInfo pi; // Version pi = pm.getPackageInfo(app.getPackageName(), 0); G.APP_VERSION = pi.versionName; // Package name G.APP_PACKAGE = pi.packageName; // Files dir for storing the stack traces G.FILES_PATH = app.getFilesDir().getAbsolutePath(); // Device model G.PHONE_MODEL = android.os.Build.MODEL; // Android version G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; } catch (NameNotFoundException e) { e.printStackTrace(); } Log.d(TAG, "APP_VERSION: " + G.APP_VERSION); Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE); Log.d(TAG, "FILES_PATH: " + G.FILES_PATH); 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:de.duenndns.ssl.MemorizingTrustManager.java
void init(Context m) { master = m;/*from w ww.j av a 2 s . co m*/ masterHandler = new Handler(m.getMainLooper()); notificationManager = (NotificationManager) master.getSystemService(Context.NOTIFICATION_SERVICE); Application app; if (m instanceof Application) { app = (Application) m; } else if (m instanceof Service) { app = ((Service) m).getApplication(); } else if (m instanceof Activity) { app = ((Activity) m).getApplication(); } else throw new ClassCastException("MemorizingTrustManager context must be either Activity or Service!"); File dir = app.getDir(KEYSTORE_DIR, Context.MODE_PRIVATE); keyStoreFile = new File(dir + File.separator + KEYSTORE_FILE); poshCacheDir = app.getFilesDir().getAbsolutePath() + "/posh_cache/"; appKeyStore = loadAppKeyStore(); }
From source file:com.hichinaschool.flashcards.async.Connection.java
private Payload doInBackgroundSendFeedback(Payload data) { // Log.i(AnkiDroidApp.TAG, "doInBackgroundSendFeedback"); String feedbackUrl = (String) data.data[0]; String errorUrl = (String) data.data[1]; String feedback = (String) data.data[2]; ArrayList<HashMap<String, String>> errors = (ArrayList<HashMap<String, String>>) data.data[3]; String groupId = ((Long) data.data[4]).toString(); Application app = (Application) data.data[5]; boolean deleteAfterSending = (Boolean) data.data[6]; String postType = null;/*from www. j a v a2 s . c o m*/ if (feedback.length() > 0) { if (errors.size() > 0) { postType = Feedback.TYPE_ERROR_FEEDBACK; } else { postType = Feedback.TYPE_FEEDBACK; } publishProgress(postType, 0, Feedback.STATE_UPLOADING); Payload reply = Feedback.postFeedback(feedbackUrl, postType, feedback, groupId, 0, null); if (reply.success) { publishProgress(postType, 0, Feedback.STATE_SUCCESSFUL, reply.returnType, reply.result); } else { publishProgress(postType, 0, Feedback.STATE_FAILED, reply.returnType, reply.result); } } for (int i = 0; i < errors.size(); i++) { HashMap<String, String> error = errors.get(i); if (error.containsKey("state") && error.get("state").equals(Feedback.STATE_WAITING)) { postType = Feedback.TYPE_STACKTRACE; publishProgress(postType, i, Feedback.STATE_UPLOADING); Payload reply = Feedback.postFeedback(errorUrl, postType, error.get("filename"), groupId, i, app); if (reply.success) { publishProgress(postType, i, Feedback.STATE_SUCCESSFUL, reply.returnType, reply.result); } else { publishProgress(postType, i, Feedback.STATE_FAILED, reply.returnType, reply.result); } if (deleteAfterSending && (reply.success || reply.returnType == 200)) { File file = new File(app.getFilesDir() + "/" + error.get("filename")); file.delete(); } } } app = null; return data; }