2011-12-12 129 views
1

我試圖分配許可給我創建了一個文件,它是用來設置系統Settings.I我上線分配權限系統設置文件

inputStream=context.getAssets().open(fileName); 

得到一個IO異常在我的清單文件我已經分配了文件權限使用

<uses-permission android:name="android.permission.WRITE_SETTINGS"/> 

它允許讀寫系統設置文件。但仍提供Exception.Thanks。 根據要求我加入的代碼發生錯誤

public boolean copyConfigFile(String fileName) throws IOException { 
     File configFile = new File(systemDir, fileName); 
     Log.d(getClass().getSimpleName(), "Config file path :" + configFile.getAbsolutePath()); 
     Log.d(getClass().getSimpleName(), "FILE NAME::" + fileName); 
     if(!configFile.exists()){ 
      configFile.createNewFile(); 
      InputStream is = null; 
      OutputStream os = null; 
      try { 
       is = ctx.getAssets().open(fileName); 
       os = new FileOutputStream(configFile); 
       byte []fileBytes = new byte[is.available()]; 
       is.read(fileBytes); 
       os.write(fileBytes); 
       Log.d(getClass().getSimpleName(), "File copied."); 
       return true; 
      } finally { 
       if(is != null){ 
        is.close(); 
       } 
       if(os != null){ 
        os.close(); 
       } 
      } 
     }else{ 
      Log.d(getClass().getSimpleName(), "File already exist."); 
      return true; 
     } 
    } 

回答

1

嗯..研究發現,創建應保存在資產目錄和在任何地方Else.I是一個愚蠢的手

0

你試過WRITE_SECURE_SETTINGS?

或者可能是錯誤的文件路徑。您可能需要發佈更具體的代碼。

+0

之前沒有看過根據要求我加入的錯了。系統設置文件代碼發生錯誤。 – AbhishekB

+0

我已經添加了2個權限more :: <使用權限android:name =「android.permission.WRITE_SECURE_SETTINGS」/> <使用權限android:name =「android.permission.WRITE_EXTERNAL_STORAGE」/>仍然沒有結果 – AbhishekB