Context.getFilesDir
Code IndexAdd Codota to your IDE (free)

Best Java code snippets using android.content.Context.getFilesDir (Showing top 20 results out of 2,727)

  • Common ways to obtain Context
private void myMethod () {
Context c =
  • InstrumentationRegistry.getTargetContext()
  • View view;view.getContext()
  • ViewGroup parent;parent.getContext()
  • Smart code suggestions by Codota
}
origin: square/leakcanary

private File appStorageDirectory() {
 File appFilesDirectory = context.getFilesDir();
 return new File(appFilesDirectory, "leakcanary");
}
origin: facebook/stetho

private static File getBaseDir(Context context) {
 // getFilesDir() yields /data/data/<package>/files, we want the base package dir.
 return context.getFilesDir().getParentFile();
}
origin: pockethub/PocketHub

  @Provides
  @Named("cacheDir")
  File cacheDir(Context context) {
    return new File(context.getFilesDir(), "cache");
  }
}
origin: lingochamp/FileDownloader

public static File getConvertedMarkedFile(final Context context) {
  return new File(context.getFilesDir().getAbsolutePath() + File.separator
      + INTERNAL_DOCUMENT_NAME, OLD_FILE_CONVERTED_FILE_NAME);
}
origin: ACRA/acra

  @NonNull
  @Override
  public File getFile(@NonNull Context context, @NonNull String fileName) {
    return new File(context.getFilesDir(), fileName);
  }
},
origin: pockethub/PocketHub

private static File getFile(final Context context, final User organization) {
  return new File(context.getFilesDir(), "recent-repos-"
      + organization.id() + ".ser");
}
origin: facebook/stetho

public void cleanupFiles() {
 for (File file : mContext.getFilesDir().listFiles()) {
  if (file.getName().startsWith(FILENAME_PREFIX)) {
   if (!file.delete()) {
    LogRedirector.w(TAG, "Failed to delete " + file.getAbsolutePath());
   }
  }
 }
 LogRedirector.i(TAG, "Cleaned up temporary network files.");
}
origin: commonsguy/cw-omnibus

@Override
protected long getDataLength(Uri uri) {
 File f=new File(getContext().getFilesDir(), uri.getPath());
 return(f.length());
}
origin: commonsguy/cw-omnibus

@Override
protected long getDataLength(Uri uri) {
 File f=new File(getContext().getFilesDir(), uri.getPath());
 return(f.length());
}
origin: amitshekhariitbhu/Fast-Android-Networking

public static String getRootDirPath(Context context) {
  if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
    File file = ContextCompat.getExternalFilesDirs(context.getApplicationContext(), null)[0];
    return file.getAbsolutePath();
  } else {
    return context.getApplicationContext().getFilesDir().getAbsolutePath();
  }
}
origin: markzhai/AndroidPerformanceMonitor

static String getPath() {
  String state = Environment.getExternalStorageState();
  String logPath = BlockCanaryInternals.getContext()
      == null ? "" : BlockCanaryInternals.getContext().providePath();
  if (Environment.MEDIA_MOUNTED.equals(state)
      && Environment.getExternalStorageDirectory().canWrite()) {
    return Environment.getExternalStorageDirectory().getPath() + logPath;
  }
  return getContext().provideContext().getFilesDir() + BlockCanaryInternals.getContext().providePath();
}
origin: robolectric/robolectric

@Test
public void openFileOutput_shouldReturnAFileOutputStream() throws Exception {
 File file = new File("__test__");
 String fileContents = "blah";
 try (FileOutputStream fileOutputStream = context.openFileOutput("__test__", Context.MODE_PRIVATE)) {
  fileOutputStream.write(fileContents.getBytes(UTF_8));
 }
 try (FileInputStream fileInputStream = new FileInputStream(new File(context.getFilesDir(), file.getName()))) {
  byte[] readBuffer = new byte[fileContents.length()];
  fileInputStream.read(readBuffer);
  assertThat(new String(readBuffer, UTF_8)).isEqualTo(fileContents);
 }
}
origin: robolectric/robolectric

 @Override
 public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
  final File file =
    new File(ApplicationProvider.getApplicationContext().getFilesDir(), "test_file");
  try {
   file.createNewFile();
  } catch (IOException e) {
   throw new RuntimeException("error creating new file", e);
  }
  return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
 }
}
origin: robolectric/robolectric

@Test
public void openFileInput_shouldReturnAFileInputStream() throws Exception {
 String fileContents = "blah";
 File file = new File(context.getFilesDir(), "__test__");
 try (Writer fileWriter = Files.newBufferedWriter(file.toPath(), UTF_8)) {
  fileWriter.write(fileContents);
 }
 try (FileInputStream fileInputStream = context.openFileInput("__test__")) {
  byte[] bytes = new byte[fileContents.length()];
  fileInputStream.read(bytes);
  assertThat(bytes).isEqualTo(fileContents.getBytes(UTF_8));
 }
}
origin: robolectric/robolectric

@Before
public void setUp() throws Exception {
 file = new File(ApplicationProvider.getApplicationContext().getFilesDir(), "test");
 FileOutputStream os = new FileOutputStream(file);
 os.close();
 readOnlyFile =
   new File(ApplicationProvider.getApplicationContext().getFilesDir(), "test_readonly");
 os = new FileOutputStream(readOnlyFile);
 os.write(READ_ONLY_FILE_CONTENTS);
 os.close();
 assertThat(readOnlyFile.setReadOnly()).isTrue();
}
origin: robolectric/robolectric

@Test
public void getFilesDir_shouldCreateDirectory() throws Exception {
 assertThat(context.getFilesDir().exists()).isTrue();
}
origin: robolectric/robolectric

@Test
public void deleteFile_shouldReturnFalse() throws IOException {
 File filesDir = context.getFilesDir();
 File file = new File(filesDir, "test.txt");
 boolean successfully = context.deleteFile(file.getName());
 assertThat(successfully).isFalse();
}
origin: robolectric/robolectric

@Test
public void deleteFile_shouldReturnTrue() throws IOException {
 File filesDir = context.getFilesDir();
 File file = new File(filesDir, "test.txt");
 boolean successfully = file.createNewFile();
 assertThat(successfully).isTrue();
 successfully = context.deleteFile(file.getName());
 assertThat(successfully).isTrue();
}
origin: robolectric/robolectric

@Test
public void fileList() throws Exception {
 assertThat(context.fileList()).isEqualTo(context.getFilesDir().list());
}
origin: robolectric/robolectric

@Test
public void testAutoCloseOutputStream() throws Exception {
 File f = new File(ApplicationProvider.getApplicationContext().getFilesDir(), "outfile");
 ParcelFileDescriptor pfd = ParcelFileDescriptor.open(f, -1);
 ParcelFileDescriptor.AutoCloseOutputStream os =
   new ParcelFileDescriptor.AutoCloseOutputStream(pfd);
 os.close();
 assertThat(pfd.getFileDescriptor().valid()).isFalse();
}
android.contentContextgetFilesDir

Popular methods of Context

  • getPackageName
  • getResources
  • getSystemService
  • obtainStyledAttributes
  • getApplicationContext
  • getString
  • getPackageManager
  • startActivity
  • getContentResolver
  • getSharedPreferences
  • getAssets
  • getTheme
  • getAssets,
  • getTheme,
  • getCacheDir,
  • startService,
  • sendBroadcast,
  • registerReceiver,
  • getApplicationInfo,
  • unregisterReceiver,
  • getExternalCacheDir

Popular in Java

  • Creating JSON documents from java classes using gson
  • setRequestProperty (URLConnection)
  • notifyDataSetChanged (ArrayAdapter)
  • getApplicationContext (Context)
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no

For IntelliJ IDEA,
Android Studio or Eclipse

  • Search for JavaScript code betaCodota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutBlogContact Us
  • Plugin user guideTerms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)