diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 4d76925f2a6..a6e353426c2 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -195,7 +195,13 @@ public void sendDownloadedFile(OCFile file) { String[] packagesToExclude = new String[]{mFileActivity.getPackageName()}; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - mFileActivity.startActivity(Intent.createChooser(sendIntent, "")); + Intent shareSheetIntent = new ShareSheetHelper().getShareSheetIntent( + sendIntent, + mFileActivity.getApplicationContext(), + packagesToExclude + ); + + mFileActivity.startActivity(shareSheetIntent); } else { DialogFragment chooserDialog = ShareLinkToDialog.newInstance(sendIntent, packagesToExclude); chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG); @@ -448,7 +454,13 @@ private void shareLink(String link) { String[] packagesToExclude = new String[]{mFileActivity.getPackageName()}; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - mFileActivity.startActivity(Intent.createChooser(intentToShareLink, "")); + Intent shareSheetIntent = new ShareSheetHelper().getShareSheetIntent( + intentToShareLink, + mFileActivity.getApplicationContext(), + packagesToExclude + ); + + mFileActivity.startActivity(shareSheetIntent); } else { DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intentToShareLink, packagesToExclude); chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG); diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/ShareSheetHelper.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/ShareSheetHelper.kt new file mode 100644 index 00000000000..5644fa0e396 --- /dev/null +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/helpers/ShareSheetHelper.kt @@ -0,0 +1,61 @@ +/** + * ownCloud Android client application + * + * @author Abel GarcĂ­a de Prada + * Copyright (C) 2020 ownCloud GmbH. + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.ui.helpers + +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.content.pm.ResolveInfo +import android.os.Build +import android.os.Parcelable +import androidx.annotation.RequiresApi +import java.util.ArrayList + +class ShareSheetHelper { + + @RequiresApi(Build.VERSION_CODES.N) + fun getShareSheetIntent( + intent: Intent, + context: Context, + packagesToExclude: Array + ): Intent { + + // Get excluding specific targets by component. We want to hide oC targets. + val resInfo: List = + context.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY) + val excludeLists = ArrayList() + if (resInfo.isNotEmpty()) { + for (info in resInfo) { + val activityInfo = info.activityInfo + for (packageToExclude in packagesToExclude) { + if (activityInfo != null && activityInfo.packageName == packageToExclude) { + excludeLists.add(ComponentName(activityInfo.packageName, activityInfo.name)) + } + } + } + } + + // Return a new ShareSheet intent + return Intent.createChooser(intent, "").apply { + putExtra(Intent.EXTRA_EXCLUDE_COMPONENTS, excludeLists.toArray(arrayOf())) + } + } +}