From a361a32234ea9e73093cbf262082cb198c0409ac Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 24 Jun 2020 14:18:44 +0300 Subject: [PATCH] handle share text intent --- OsmAnd/AndroidManifest.xml | 2 +- .../net/osmand/plus/helpers/IntentHelper.java | 39 ++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 4b8ed91a87..5a0082b792 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -394,7 +394,7 @@ - + diff --git a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java index 6395a85a96..d58271a27c 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java @@ -56,7 +56,7 @@ public class IntentHelper { applied = parseOpenGpxIntent(); } if (!applied) { - applied = parseExtraTextIntent(); + applied = parseSendIntent(); } return applied; } @@ -257,21 +257,32 @@ public class IntentHelper { intent.setData(null); } - private boolean parseExtraTextIntent() { + private boolean parseSendIntent() { Intent intent = mapActivity.getIntent(); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M && intent != null) { - CharSequence text = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT); - if (!Algorithms.isEmpty(text)) { - return QuickSearchDialogFragment.showInstance( - mapActivity, - text.toString(), - null, - QuickSearchDialogFragment.QuickSearchType.REGULAR, - QuickSearchDialogFragment.QuickSearchTab.CATEGORIES, - null - ); + if (intent != null) { + String action = intent.getAction(); + String type = intent.getType(); + if (Intent.ACTION_SEND.equals(action) && type != null) { + if ("text/plain".equals(type)) { + return handleSendText(intent); + } } } return false; } -} \ No newline at end of file + + private boolean handleSendText(Intent intent) { + String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); + if (!Algorithms.isEmpty(sharedText)) { + return QuickSearchDialogFragment.showInstance( + mapActivity, + sharedText, + null, + QuickSearchDialogFragment.QuickSearchType.REGULAR, + QuickSearchDialogFragment.QuickSearchTab.CATEGORIES, + null + ); + } + return false; + } +}