2014-09-29 29 views
0

我試圖讀取另一個Android應用程序創建的文件。EACCES(權限被拒絕)。試圖訪問由另一個應用程序創建的文件Android

File file = new File("/data/data/air.br.com.screencorp.MobilePlayer/br.com.screencorp.MobilePlayer/Local Store/token"); 
    FileInputStream fis = null; 

    try { 
     fis = new FileInputStream(file); 

     Log.d("SIZE", "Total file size to read (in bytes) : " 
       + fis.available()); 

     int content; 
     StringBuilder token = new StringBuilder(); 

     while ((content = fis.read()) != -1) { 
      token.append((char) content); 
     } 

     Log.d("TOKEN", token.toString()); 

    } catch (IOException e) { 
     e.printStackTrace(); 
    } finally { 
     try { 
      if (fis != null) 
       fis.close(); 
     } catch (IOException ex) { 
      ex.printStackTrace(); 
     } 
    } 

我不知道爲什麼,但我不允許訪問該文件。我的清單上有READ_EXTERNAL_STORAGE權限。

我應該用SharedPreferences

謝謝。

回答

1

其他應用程序的數據無法從您的應用程序訪問私人數據。這是android的安全模型。應用程序應該已經設置了文件的MODE_WORLD_READABLE權限,只有這樣才能訪問文件

+0

那麼我應該使用'SharedPreferences'來交換應用程序中的數據? – 2014-09-29 02:31:07

+0

我不認爲sharedpreferences是交換數據的正確方法。您需要根據您的要求使用提供商,意向和外部存儲 – nandeesh 2014-09-29 03:00:49

相關問題