Tuesday, 6 August 2013

How to read a config file in SD card with SharedPreferences?

How to read a config file in SD card with SharedPreferences?

http://stackoverflow.com/a/9172615/2653579
public class Calc extends Activity {
public static final String PREFS_NAME = "MyPrefsFile";
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
. . .
// Restore preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String ipAddress = settings.getString("IPAddress", "");
int port = settings.getInt("port", 0);
int title = settings.getString("Title", "");
}
I found that code for read values from a config file and i cant make it to
read a file from the SD Card. I tried this way:
static File GPSCfgFile = new File(Environment.getExternalStorageDirectory()
+ "/Config/GPSLogService.cfg");
public static final String PREFS_NAME = String.valueOf(GPSCfgFile);
When i starting my service, it stops unexpectedly. This was in the logcat:
FATAL EXCEPTION: main
GPSLogService.cfg.xml contains a path separator
How can i make it to read that file from the SD card?

No comments:

Post a Comment