From 63a04c9e82d15238b83c52f1ba539586caf865a8 Mon Sep 17 00:00:00 2001 From: macearl Date: Thu, 19 Jan 2023 23:49:22 +0100 Subject: [PATCH] remove deprecated getExternalStorageDirectory in favour of (scoped) getExternalFilesDir, fixes backup/restore preferences --- .../klinker/android/twitter_l/settings/PrefFragment.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/klinker/android/twitter_l/settings/PrefFragment.java b/app/src/main/java/com/klinker/android/twitter_l/settings/PrefFragment.java index 915eb87a9..921b96c77 100644 --- a/app/src/main/java/com/klinker/android/twitter_l/settings/PrefFragment.java +++ b/app/src/main/java/com/klinker/android/twitter_l/settings/PrefFragment.java @@ -424,10 +424,11 @@ public boolean onPreferenceClick(Preference arg0) { .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - File des = new File(Environment.getExternalStorageDirectory() + "/Talon/backup.prefs"); + String desPath = context.getExternalFilesDir(null).getAbsolutePath() + "/backup.prefs"; + File des = new File(desPath); IOUtils.saveSharedPreferencesToFile(des, context); - Toast.makeText(context, context.getResources().getString(R.string.backup_success) + ": /Talon/backup.prefs", Toast.LENGTH_LONG).show(); + Toast.makeText(context, context.getResources().getString(R.string.backup_success) + ": " + desPath, Toast.LENGTH_LONG).show(); } }) .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { @@ -450,7 +451,7 @@ public void onClick(DialogInterface dialogInterface, int i) { @Override public boolean onPreferenceClick(Preference arg0) { - File des = new File(Environment.getExternalStorageDirectory() + "/Talon/backup.prefs"); + File des = new File(context.getExternalFilesDir(null).getAbsolutePath() + "/backup.prefs"); String authenticationToken1 = sharedPrefs.getString("authentication_token_1", "none"); String authenticationTokenSecret1 = sharedPrefs.getString("authentication_token_secret_1", "none");