2013-04-02 2 views
1

내 안드로이드 코드로 sharedpreferences 파일을 만들고 있습니다. 그런 다음 해당 파일을 내 코드로 전자 메일로 보내려고합니다. 이를 위해 sharedpreferences 파일의 경로에 액세스해야합니다. 내가 사용하고있는 코드는 다음과 같습니다. 그러나 그것은 효과가없는 것처럼 보입니다. 이메일을 열 수는 있지만 파일을 가져올 수 없기 때문에 첨부 파일이 없습니다. 누군가 내게 어떤 해결책을 제안 할 수 있습니까?sharedpreferences 파일의 파일 경로를 얻으십시오

File f = getDatabasePath("userPrefsFile.xml"); 
String filelocation=f.getAbsolutePath(); 
Intent email = new Intent(Intent.ACTION_SEND); 
email.setType("application/xml"); 
String[] to = {"[email protected]"}; 
email.putExtra(Intent.EXTRA_EMAIL, to); 
email.putExtra(Intent.EXTRA_STREAM,filelocation); 
email.putExtra(Intent.EXTRA_SUBJECT,"test file send"); 
startActivity(Intent.createChooser(email, "Send email")); 

답변

3

그래서 된 SharedPreferences 파일은

/data/data/your.package/shared_prefs 

그래서 당신은 위의 경로를 사용할 필요가 디렉토리에 있습니다.

의사 코드 : 당신이 getDatabasePath()를 사용할 수없는 이유

File root = new File("/data/data/your.package/shared_prefs"); 
if (root.isDirectory()) { 
    for (File child: root.listFiles()) { 
     Toast.makeText(this, child.getPath(), Toast.LENGTH_SHORT).show(); 
    } 
} 

이유는 같은 문제도 getFileStreamPath() 관련이 1

/data/data/your.package/databases/ 


1 데이터베이스 폴더를 반환

을 반환하는 메서드
/data/data/your.package/files 
관련 문제