public class LocalStorageManager {
private static final int mPrivateMode = Context.MODE_PRIVATE;
private static final int mPublicMode = Context.MODE_WORLD_WRITEABLE | Context.MODE_WORLD_READABLE;
private static final String prefix = "app_";
/data/data/パッケージ名を取得する
@param context
@return
@throws FileNotFoundException
public static final File getPackageNameDirectory (Context context) throws FileNotFoundException {
String temporary = "hoge";
StringBuilder builder = new StringBuilder();
builder.append(prefix).append(temporary);
File root = new File(context.getDir(temporary, mPrivateMode).getAbsolutePath().replace(builder.toString(), ""));
if (!root.exists()) {
throw new FileNotFoundException();
}
return root;
}
/data/data/パッケージ名/直下にpathフォルダがあるかどうか
@param context
@param path
@return
public static final File findLocalDirectory (Context context, final String path) {
try {
File find = new File(getPackageNameDirectory(context), path);
if (find.exists()) {
return find;
}
} catch (FileNotFoundException e) {
TODO
e.printStackTrace();
}
return null;
}
}