From c34279f1907d34bc70682a06c29d89b3e49fa943 Mon Sep 17 00:00:00 2001 From: Stefan Behrens Date: Thu, 18 May 2023 17:58:47 +0200 Subject: [PATCH] Fix ConvertCSV (#80) --- .../common/ConvertCsvBaseActivity.java | 20 ++++++++++++++++--- .../shopping/ui/ShoppingActivity.java | 6 ------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ShoppingList/src/main/java/org/openintents/convertcsv/common/ConvertCsvBaseActivity.java b/ShoppingList/src/main/java/org/openintents/convertcsv/common/ConvertCsvBaseActivity.java index 78aa05c..4532dcb 100644 --- a/ShoppingList/src/main/java/org/openintents/convertcsv/common/ConvertCsvBaseActivity.java +++ b/ShoppingList/src/main/java/org/openintents/convertcsv/common/ConvertCsvBaseActivity.java @@ -27,12 +27,14 @@ import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.ParcelFileDescriptor; import android.preference.PreferenceManager; import android.provider.OpenableColumns; +import android.support.annotation.RequiresApi; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; @@ -776,20 +778,32 @@ protected String getSdCardFilename(String filename) { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); Log.i(TAG, "onActivityResult"); switch (requestCode) { case REQUEST_CODE_PICK_FILE: if (resultCode == RESULT_OK && data != null) { - Uri documentUri = data.getData(); + Uri documentUri = null; + if (Build.VERSION.SDK_INT < 19) { + documentUri = data.getData(); + } else { + documentUri = data.getData(); + final int takeFlags = data.getFlags() + & (Intent.FLAG_GRANT_READ_URI_PERMISSION + | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + try { + getContentResolver().takePersistableUriPermission(documentUri, takeFlags); + } + catch (SecurityException e){ + e.printStackTrace(); + } + } if (documentUri != null) { setFileUri(documentUri); } else { setFileUriUnknown(); } - } break; } diff --git a/ShoppingList/src/main/java/org/openintents/shopping/ui/ShoppingActivity.java b/ShoppingList/src/main/java/org/openintents/shopping/ui/ShoppingActivity.java index ccbc45e..feaeeb5 100644 --- a/ShoppingList/src/main/java/org/openintents/shopping/ui/ShoppingActivity.java +++ b/ShoppingList/src/main/java/org/openintents/shopping/ui/ShoppingActivity.java @@ -197,7 +197,6 @@ public class ShoppingActivity extends DistributionLibraryFragmentActivity private static final int MENU_ITEM_STORES = Menu.FIRST + 22; private static final int MENU_UNMARK_ALL_ITEMS = Menu.FIRST + 23; private static final int MENU_SYNC_WEAR = Menu.FIRST + 25; - private static final int MENU_CONVERT_CSV = Menu.FIRST + 26; private static final int MENU_DISTRIBUTION_START = Menu.FIRST + 100; // MUST BE LAST private static final int DIALOG_ABOUT = 1; // private static final int DIALOG_TEXT_ENTRY = 2; @@ -1608,8 +1607,6 @@ public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, MENU_SYNC_WEAR, 0, R.string.sync_wear); - menu.add(0, MENU_CONVERT_CSV, 0, R.string.convert_csv); - // Add distribution menu items last. mDistribution.onCreateOptionsMenu(menu); @@ -1804,9 +1801,6 @@ public boolean onOptionsItemSelected(MenuItem item) { case MENU_SYNC_WEAR: mItemsView.pushItemsToWear(); return true; - case MENU_CONVERT_CSV: - startActivity(new Intent(this, ConvertCsvActivity.class).setData(mListUri)); - return true; default: break; }