Merge pull request #9317 from osmandapp/share_text_to_osmand

handle share text intent
This commit is contained in:
vshcherb 2020-06-25 14:25:30 +02:00 committed by GitHub
commit 795666a46d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 15 deletions

View file

@ -394,7 +394,7 @@
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>

View file

@ -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;
}
}
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;
}
}