在密码保护的SD卡中制作文件夹:android

时间:2012-05-17 11:04:43

标签: android

我将视频和图像保存在一个文件夹中..现在我想将此文件夹设为密码保护,意味着打开此文件夹时需要输入密码才能查看其中的文件
     希望在这里得到任何相关的答案...如果有任何其他可能请建议..

                     try {
                        dirName = "/mydirectory/";
                        fileName = new Long(
                                SystemClock.currentThreadTimeMillis())
                                .toString()
                                + ".png";
                    } catch (NullPointerException e) {
                        // TODO: handle exception
                    }
                    try {
                        if (android.os.Environment
                                .getExternalStorageState()
                                .equals(android.os.Environment.MEDIA_MOUNTED)) {
                            File sdCard = Environment
                                    .getExternalStorageDirectory();
                            File dir = new File(sdCard.getAbsolutePath()
                                    + dirName);
                            dir.mkdirs();

                            File file = new File(storedImagePath);

                            os = new FileOutputStream(file, true);

                            byte[] byteArray = receivedImageData.getBytes();

                            byteArray = Base64.decode(byteArray, 0);

                            os.write(byteArray);
                            os.flush();
                            os.close();

                        } else {

                        }

                    } catch (Exception e) {

                    }

1 个答案:

答案 0 :(得分:4)

我想建议一种不同/可行的方法,加密您的文件

查看this answer!

即使你成功实施了密码保护(哇!),这里有缺点,

  1. 这只会在您的应用运行时保护。
  2. SD卡应该被转移(因此你的应用程序无法始终保护SD卡上的文件)。