首页 文章

创建具有密码保护的文件夹

提问于
浏览
0

我正在尝试通过创建具有密码保护和内部音频文件的文件夹来为Android创建媒体 Logger .

但现在我只能创建其他应用程序和Android智能手机用户访问的文件夹和音频文件 .

实施密码保护的目的是为了不让其他应用程序或用户访问文件和文件夹,除非提供密码?

除了创建密码输入面板之外,有什么想法可以实现这个目的吗?

以下是我的代码 .

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;
    }
}

1 回答

  • 3

    如果您在External Storage中创建文件,那么按照设计,文件是世界可读的 . 如果您在目录中创建一个名为 .nomedia 的文件,那么媒体扫描程序将忽略其中的文件,但是如果他们去寻找它们,其他应用程序仍然可以读取它们 .

    如果您希望文件对应用程序是私有的,则需要在Internal Storage中创建 . 此处创建的文件只能由您的应用程序访问(如果我们忽略具有root设备的用户) . 但是,内部存储空间通常较少,这意味着它不适合存储大量数据,如音频文件 . 例如,7.6.2节中的the Android 4.0 compatibility definition表示设备需要在所有应用程序之间共享至少1GB的内部存储空间 . 这在Android的早期版本中并不是很多,而且较少 .

    想到的唯一另一个选择是加密存储在外部存储中的音频文件,因此当其他应用程序可以访问它们时,它们将无法播放存储的音频 . This question has an answer showing how to use CipherOutputStream to do this.

相关问题