Skip to content

Instantly share code, notes, and snippets.

@bulentsiyah
Last active May 17, 2018 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bulentsiyah/1c639d427362cd10a35dd93bf7c2e816 to your computer and use it in GitHub Desktop.
Save bulentsiyah/1c639d427362cd10a35dd93bf7c2e816 to your computer and use it in GitHub Desktop.
Dosyayı Private olarak kaydetme -- Servis gizlice kaydediyor, MainActivity de daha önce kaydedilmişleri sıralıyoruz. -- http://www.bulentsiyah.com/dosyayi-gizli-baska-uyg-tarafindan-erisilemeyek-klasore-olarak-kaydetme-android/
What is the difference between getDir and getFilesDir on Android?
getFilesDir() returns a File object to a directory that is private to your application only.
When you use openFileOutput(String, int),
the data you write is directly stored in this directory and is not accessible by any other application.
It holds your application files.
getDir() enables you to create any file or directory in the internal memory,
which is also accessible by other applications depending on the mode you create it.
openFileOutput(String, int) will not work with the output of this so you will have to use other means
of writing and reading files to deal with this directory or file.
This is more used for creating custom files other than files only used by your application.
try{
File directory = getFilesDir();
File[] files = directory.listFiles();
Log.d("Files", "Size: "+ files.length);
for (int i = 0; i < files.length; i++)
{
Log.d("Files", "FileName:" + files[i].getName());
}
}catch (Exception exp){
exp.toString();
}
Bunlar unutulmamalı
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
@Override
public void onCreate() {
super.onCreate();
try {
Date date = new Date();
String stringDate = DateFormat.getDateTimeInstance().format(date);
String sd_temp = "/" + stringDate + "callrec.3gp";
//prepareDirectory(getApplicationContext(),sd_temp);
// file = new File(dir_CallRecorder);
File dir = getFilesDir();
rec = new MediaRecorder();
rec.setAudioSource(MediaRecorder.AudioSource.MIC);
rec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
rec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
rec.setOutputFile(dir.getAbsoluteFile()+sd_temp);
rec.prepare();
rec.start();
} catch (Exception e) {
e.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment