0

I am trying to create the media recorder for Android by creating the folders with password protection and audio files inside.

But now I only can create the folder and audio files which other Apps and user of the Android smartphone to access.

The purpose of implementing password protection is to not to let other Apps or users can access the file and folders unless password is provided?

Are there any ideas how to achieve this besides creating the password entering panel?

The below is my code.

public void onClick(View view) throws Exception {
    if (count == 0) {

        tbxRecordStatus.setText("Record");
        btnRecord.setText("Stop Record");
        Toast.makeText(MainActivity.this, "Recording Starts",
                Toast.LENGTH_SHORT).show();
        String dateInString =  new SimpleDateFormat(
                "yyyy-MM-dd-HH-mm-ss").format(new Date()).toString();
        String fileName = "TasB_" + dateInString + " record.3gp";
        SDCardpath = Environment.getExternalStorageDirectory();
        myDataPath = new File(SDCardpath.getAbsolutePath()  + "/My Recordings");
        if (!myDataPath.exists())
            myDataPath.mkdir();

        audiofile = new File(myDataPath + "/" + fileName);
        recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setAudioEncodingBitRate(16);
        recorder.setAudioSamplingRate(44100);
        recorder.setOutputFile(audiofile.getAbsolutePath());



        try
        {
         recorder.prepare();
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        recorder.start();
        count++;

    } else {

        tbxRecordStatus.setText("Stop");
        btnRecord.setText("Start Record");
        Toast.makeText(MainActivity.this, "Recording Stops",
                Toast.LENGTH_SHORT).show();
        if (recorder != null) {
            recorder.stop();
            recorder.release();
            recorder = null;

        } else {
            tbxRecordStatus.setText("Warning!");
            Toast.makeText(MainActivity.this, "Record First",
                    Toast.LENGTH_SHORT).show();
        }
        count = 0;
    }
}
Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141

1 Answers1

3

If you create files in External Storage then by design the files are world readable. If you create a file called .nomedia in the directory then the media scanner will ignore the files in there but other applications could still read them if they go looking for them.

If you want your files to be private to your application then they need to created in Internal Storage. Files created here are only accessible by your application (if we ignore users with rooted devices). However, there is usually a lot less space available in Internal storage which means it's not ideal for storing large amounts of data such as audio files. For example, the Android 4.0 compatibility definition in section 7.6.2 says devices need a minimum of 1GB of internal storage shared between all applications. This isn't a lot and was less in earlier releases of Android.

The only other option that springs to mind would be to encrypt the audio files stored in External Storage, so whilst other apps could access them they wouldn't be able to play the stored audio. This question has an answer showing how to use CipherOutputStream to do this.

Community
  • 1
  • 1
David Webb
  • 190,537
  • 57
  • 313
  • 299
  • If I use encryption method, can the user delete , copy , or move the files ? – Jeff Bootsholz May 02 '13 at 09:30
  • 1
    @RajuGujarati - yes, the user can do whatever they like with the files on External Storage. – David Webb May 02 '13 at 09:35
  • So would it be safer if I save the file into the Internal Storage of my Samsung Tablet which has 11GBs with encryption ? – Jeff Bootsholz May 02 '13 at 09:38
  • 1
    If you use Internal Storage you won't need to encrypt the files as only your app can access them. – David Webb May 02 '13 at 09:43
  • Does it mean that unless I am using file explorer to show unhide files explicitly , the file cannot be accessed easily ? – Jeff Bootsholz May 02 '13 at 12:58
  • If the file is Internal Storage it is only accessible via your App unless the device has been rooted. Each App gets its own User ID and files in Internal Storage can be created to be only read by that user. – David Webb May 02 '13 at 13:13
  • @DaveWebb if i use encryption for our app folder then can i share images from encrypted folder or may i need to decrypt it first and then share image can u pls help me how can i do that ? – Erum Dec 20 '14 at 12:10