1

This is my code to store a value in sharedPreferences

SharedPreferences.Editor editor = context.getSharedPreferences("My_Table_name", Context.MODE_PRIVATE).edit();
    editor.putString("my_key", "how Are You Bro...");
    editor.apply();
    editor.commit();

and I want to save it like this

File file = new File(Environment.getExternalStorageDirectory()+ "/.System/My_Table_Name");

    SharedPreferences.Editor editor = context.getSharedPreferences(file, Context.MODE_PRIVATE).edit();
    editor.putString("My_Key", "how Are You Bro...");
    editor.apply();
    editor.commit();

how can I do this?

 getSharedPreferences(File file, int mode);

This method is available, but it's been removed. Earlier I've tried to copy this file, but for this method the app needs super user permission (rooted device).

What should I use?

Dimitar
  • 4,402
  • 4
  • 31
  • 47
Soni_ji
  • 115
  • 1
  • 12
  • 4
    Possible duplicate of [Is There A Way To Store SharedPreferences to SDcard?](https://stackoverflow.com/questions/43312275/is-there-a-way-to-store-sharedpreferences-to-sdcard) – FarshidABZ Dec 26 '17 at 12:48
  • I do not think there is a way of doing that. SharedPreferences bydefault saves at `/data/data/YOUR_PACKAGE_NAME/shared_prefs/`. – ADM Dec 26 '17 at 12:50
  • but SharedPreferences block "getSharedPreferences(File file, int mode);" this method some time before so may be is there any other solution available – Soni_ji Dec 26 '17 at 13:02
  • 1
    `Earlier I've tried to copy this file, but for this method the app needs super user permission (rooted device).`. No. Not at all. An app can easily copy its shared preferences files to external storage. – greenapps Dec 26 '17 at 18:25
  • thanks bro it's working well for me and thank you for save my time.... – Soni_ji Dec 28 '17 at 08:03

0 Answers0