Skip to content

Commit

Permalink
Return content:// instead of file:// based URIs for share inten… (#1812)
Browse files Browse the repository at this point in the history
Return content:// instead of file:// based URIs for share intents
  • Loading branch information
EmmanuelMess committed Jan 21, 2020
1 parent 7f03ccf commit a7ad4ae
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
11 changes: 0 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,6 @@
</intent-filter>
</receiver>

<provider
android:authorities="${applicationId}.FILE_PROVIDER"
android:name=".utils.GenericFileProvider"
android:exported="false"
android:grantUriPermissions="true">

<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.amaze.filemanager"
Expand Down

This file was deleted.

4 changes: 3 additions & 1 deletion app/src/main/java/com/amaze/filemanager/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.core.graphics.drawable.DrawableCompat;
import android.text.format.DateUtils;
import android.util.DisplayMetrics;
Expand All @@ -43,6 +44,7 @@
import com.amaze.filemanager.R;
import com.amaze.filemanager.activities.MainActivity;
import com.amaze.filemanager.filesystem.HybridFileParcelable;
import com.amaze.filemanager.utils.files.FileUtils;

import java.io.File;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -215,7 +217,7 @@ public static Uri getUriForBaseFile(Context context, HybridFileParcelable baseFi
case ROOT:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

return GenericFileProvider.getUriForFile(context, GenericFileProvider.PROVIDER_NAME,
return FileProvider.getUriForFile(context, FileUtils.FILE_PROVIDER_AUTHORITY,
new File(baseFile.getPath()));
} else {
return Uri.fromFile(new File(baseFile.getPath()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2014 Arpit Khurana <[email protected]>, Vishal Nehra <[email protected]>,
* Marcin Zasuwa <[email protected]>
* Copyright (C) 2014-2020 Arpit Khurana <[email protected]>,
* Vishal Nehra <[email protected]>, Marcin Zasuwa <[email protected]>,
* Raymond Lai <airwave209gt at gmail.com> and contributors.
*
* This file is part of Amaze File Manager.
*
Expand Down Expand Up @@ -97,6 +98,7 @@
*/
public class FileUtils {

public static final String FILE_PROVIDER_AUTHORITY = "com.amaze.filemanager";
public static final String NOMEDIA_FILE = ".nomedia";

public static long folderSize(File directory, OnProgressUpdate<Long> updateState) {
Expand Down Expand Up @@ -357,7 +359,7 @@ public static void shareFiles(ArrayList<File> a, Activity c,AppTheme appTheme,in
ArrayList<Uri> uris = new ArrayList<>();
boolean b = true;
for (File f : a) {
uris.add(Uri.fromFile(f));
uris.add(FileProvider.getUriForFile(c, FILE_PROVIDER_AUTHORITY, f));
}

String mime = MimeTypes.getMimeType(a.get(0).getPath(), a.get(0).isDirectory());
Expand Down Expand Up @@ -523,7 +525,7 @@ public static Uri fileToContentUri(Context context, File file, Intent chooserInt
}

chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_GRANT_READ_URI_PERMISSION);
return FileProvider.getUriForFile(context, "com.amaze.filemanager", file);
return FileProvider.getUriForFile(context, FILE_PROVIDER_AUTHORITY, file);
}

private static Uri fileToContentUri(Context context, String path, boolean isDirectory, String volume) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* Copyright (C) 2015-2020 Arpit Khurana <[email protected]>,
* Vishal Nehra <[email protected]>, Rémi Piotaix <[email protected]>,
* John Carlson <[email protected]>, Emmanuel Messulam<[email protected]>,
* James Downs <[email protected]>, Bowie Chen <[email protected]>,
* Raymond Lai <airwave209gt at gmail.com> and contributors.
*
* This file is part of Amaze File Manager.
*
* Amaze File Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 <http://www.gnu.org/licenses/>.
*/

package com.amaze.filemanager.utils.share;

import android.app.Activity;
Expand Down Expand Up @@ -53,9 +76,9 @@ protected Void doInBackground(String... strings) {
arrayList1.add(resInfo.loadLabel(packageManager).toString());
if (packageName.contains("android.bluetooth")) bluetooth_present = true;
Intent intent = new Intent();
System.out.println(resInfo.activityInfo.packageName + "\t" + resInfo.activityInfo.name);
intent.setComponent(new ComponentName(packageName, resInfo.activityInfo.name));
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType(mime);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, arrayList);
intent.setPackage(packageName);
Expand Down

0 comments on commit a7ad4ae

Please sign in to comment.