0

Question: Is it possible to use shared preferences on a Samsung Tab E, Android 7.1.1, API 25. Here is my state, results and research so far...

SharedPreferences are not reading from Samsung Tab E, Android 7.1.1, API 25 but works on HUAWEI T377W, Android 10, API 29.

In OnCreate...

SharedPreferences sharedPreferences =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        geoCount = sharedPreferences.getInt("geoCount", 0);

In public void finish...

SharedPreferences sharedPreferences =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("geoCount", geoCount);
        editor.apply();     

Followup question: Are OnCreate and finish the best places for this code?

In the both devices the preferences file is not findable...

internal storage/Android/data/gmd.com.mickwebsite.metaquest/files/MetaQuest "nothing"

In Android Studio, Electric Eel, File Explorer... Found it with a correct value in the Huawei phone at... /data/data/gmd.com.mickwebsite.metaquest/shared_prefs

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <int name="geoCount" value="53" />
</map>

Samsung Tablet. Not findable here... /data/data/gmd.com.mickwebsite.myapplication "run as: could not set capabilities: operation not permitted" <- in RED print

There are other file paths that lead to my app but all have the same error message. I googled the error message - I guess I am just unlucky having a Samsung device. Is there a way to get the preferences working? I am assuming that this condition causes my preferences problem in addition to the problems posted by many others about "run as".

Mick
  • 663
  • 1
  • 9
  • 18
  • Dont use putInt()/getInt(). Use putString()/getString(). And onFinisch() is the worst place to do it. If you wanna test then do all on button clicks first. – blackapps Mar 09 '23 at 20:19
  • The preference xml file is always in new File(getFilesDir().getParentFile(), "shared_prefs").getAbsolutePath(). – blackapps Mar 09 '23 at 20:20
  • I think that the actual technical problem is with the Samsung phone as I have read many posts about a similar problem with "run as" that is caused by changes made specifically by Samsung. I am hoping that someone familiar with this problem will comment. If finish is the worst place what would be a better choice? Finish seems obvious from the name but I guess there are technical difficulties that I am not yet familiar with? I could use some standard I-O to read and write to the file using the path you provided, assuming it is writeable, but I prefer to stick with standard practices :) – Mick Mar 09 '23 at 22:22
  • Ofcourse you should not write to that file yourself. – blackapps Mar 10 '23 at 07:19

1 Answers1

0

Problem seems to have "gone away". I do not know what I did to help that along. I thought that I had thoroughly tested and thought this out before I posted - I must have missed something:(

Mick
  • 663
  • 1
  • 9
  • 18