본문 바로가기

자료

[Android]파일 퍼미션 주기

public class st extends Activity {
   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.main);
        File f = new File("/dev/alarm");
  try {
   int i = changePermissons(f,0777);
  } catch (Exception e) {
   e.printStackTrace();
  }
}
   
 public int changePermissons(File path, int mode) throws Exception {
  Class<?> fileUtils = Class.forName("android.os.FileUtils");
  Method setPermissions = fileUtils.getMethod("setPermissions",
    String.class, int.class, int.class, int.class);

  return (Integer) setPermissions.invoke(null, path.getAbsolutePath(),
    mode, -1, -1);
 }
}
간혹 안드로이드개발시 파일에 권한 설정을 해줘야 할때가 있다.
그럴때 이를 사용하면.. 유용할듯..

단, 루트 권한의 파일은 설정 할 수 없다.

'자료' 카테고리의 다른 글

윈도우 암호 삭제  (0) 2016.07.29
자동차 도색 순서  (0) 2012.04.23
비쥬얼 스튜디오 2005 단축키  (0) 2011.01.13
방화벽 설정  (0) 2010.06.08
소스 사이트  (0) 2010.03.24