2

I have developed on Sip based application for making and receiving a call. And chat feature is also included in this application.

My application runs fine in on Samsung Galaxy y and Sony Ericsson's ICS version. but while using the application on Samsung Galaxy S2 the user is not get registered.its gives me wrong password Error on Asterisk.

So that means its unable get value from sharedpreferences or its doesn't stores the value on the device.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Juned
  • 6,290
  • 7
  • 45
  • 93

2 Answers2

2

Yeah, it is a massive pain but as far as I can tell you can't use SharedPreferences on Samsung Galaxy S1/S2 phones. No explanation :( Massive pain Error creating SharedPreferences - couldn't create directory for SharedPreferences file

Don't know how apps that do appear to save get round it - maybe they use a database.

How I have done it: Creation:

Editor editor = getSharedPreferences(Constants.SaveDataName, MODE_PRIVATE).edit();

editor.putString(Constants.SaveDataName, xmlString);
editor.commit();

Loading:

getSharedPreferences(Constants.SaveDataName, MODE_PRIVATE).getString(Constants.SaveDataName, "");

If relevant: this is in a service.

Community
  • 1
  • 1
T. Kiley
  • 2,752
  • 21
  • 30
  • thanks for your answer but what about @Alborz comment. see second comment ! – Juned Jun 01 '12 at 10:20
  • Interesting, how are you creating/editing your SharedPrefs, maybe it can be done a specific way? Creation: Editor editor = getSharedPreferences(Constants.SaveDataName, MODE_PRIVATE).edit(); editor.putString(Constants.SaveDataName, xmlString); Log.d(Constants.MsgInfo, "Saving: " + xmlString); editor.commit(); Loading: getSharedPreferences(Constants.SaveDataName, MODE_PRIVATE).getString(Constants.SaveDataName, ""); If relevant: this is in a service. – T. Kiley Jun 01 '12 at 10:23
  • 1
    @juned, let me get home and I will share the exact same code I am using for sharedPref that is working well on two diffrent SGS2 devices. – theAlse Jun 01 '12 at 10:35
  • @juned I forgot about this, sorry. will do tonight! – theAlse Jun 04 '12 at 08:09
0

@juned, now that I look at the code I see nothing special. Anyhow here are some parts of the code that had to do with sharedPref.

setting SharedPref

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    final SharedPreferences.Editor editor = preferences.edit();
    editor.putFloat("longitude", (float)location.getLongitude());
    editor.putFloat("latitude", (float)location.getLatitude());
    editor.commit();

and fetching

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    GeoPoint userLocationPoint = new GeoPoint((int) (sharedPreferences.getFloat("latitude", (float) 0.0) * 1E6),
            (int) (sharedPreferences.getFloat("longitude", (float) 0.0) * 1E6));
theAlse
  • 5,577
  • 11
  • 68
  • 110