Merge pull request #1451 from nextcloud/bugfix/1415/share_from_browser

Share from a browser should share the page URL
This commit is contained in:
Andy Scherzinger 2021-07-12 10:46:24 +02:00 committed by GitHub
commit 725c7a1f20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -842,20 +842,29 @@ public class ConversationsListController extends BaseController implements Searc
if (Intent.ACTION_SEND.equals(intent.getAction()) if (Intent.ACTION_SEND.equals(intent.getAction())
|| Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) { || Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
try { try {
if (intent.getClipData() != null) { String mimeType = intent.getType();
for (int i = 0; i < intent.getClipData().getItemCount(); i++) { if ("text/plain".equals(mimeType) && (intent.getStringExtra(Intent.EXTRA_TEXT) != null)) {
ClipData.Item item = intent.getClipData().getItemAt(i); // Share from Google Chrome sets text/plain MIME type, but also provides a content:// URI
if (item.getUri() != null) { // with a *screenshot* of the current page in getClipData().
filesToShare.add(intent.getClipData().getItemAt(i).getUri().toString()); // Here we assume that when sharing a web page the user would prefer to send the URL
} else if (item.getText() != null) { // of the current page rather than a screenshot.
textToPaste = intent.getClipData().getItemAt(i).getText().toString(); textToPaste = intent.getStringExtra(Intent.EXTRA_TEXT);
break;
} else {
Log.w(TAG, "datatype not yet implemented for share-to");
}
}
} else { } else {
filesToShare.add(intent.getData().toString()); if (intent.getClipData() != null) {
for (int i = 0; i < intent.getClipData().getItemCount(); i++) {
ClipData.Item item = intent.getClipData().getItemAt(i);
if (item.getUri() != null) {
filesToShare.add(item.getUri().toString());
} else if (item.getText() != null) {
textToPaste = item.getText().toString();
break;
} else {
Log.w(TAG, "datatype not yet implemented for share-to");
}
}
} else {
filesToShare.add(intent.getData().toString());
}
} }
if (filesToShare.isEmpty() && textToPaste.isEmpty()) { if (filesToShare.isEmpty() && textToPaste.isEmpty()) {
Toast.makeText(context, context.getResources().getString(R.string.nc_common_error_sorry), Toast.makeText(context, context.getResources().getString(R.string.nc_common_error_sorry),