Fix attachment issues on pre-lollipop devices

pull/795/head
Alex Baker 6 years ago
parent faff1dcc08
commit d74f6d457a

@ -228,6 +228,16 @@
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true"
android:name="org.tasks.files.NNFileProvider">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths"/>
</provider>
<provider
android:authorities="${applicationId}.file_provider"
android:exported="false"
android:grantUriPermissions="true"
android:name="androidx.core.content.FileProvider">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"

@ -9,7 +9,7 @@ import org.tasks.BuildConfig;
public final class Constants {
public static final String FILE_PROVIDER_AUTHORITY = BuildConfig.APPLICATION_ID + ".provider";
public static final String FILE_PROVIDER_AUTHORITY = BuildConfig.APPLICATION_ID + ".file_provider";
/** Notification Manager id for timing */
public static final int NOTIFICATION_TIMER = -2;

@ -58,10 +58,10 @@ public class CameraActivity extends InjectingAppCompatActivity {
throw new RuntimeException("Invalid Uri");
}
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(
MediaStore.EXTRA_OUTPUT,
Uri shared =
FileProvider.getUriForFile(
this, Constants.FILE_PROVIDER_AUTHORITY, new File(uri.getPath())));
this, Constants.FILE_PROVIDER_AUTHORITY, new File(uri.getPath()));
intent.putExtra(MediaStore.EXTRA_OUTPUT, shared);
if (atLeastLollipop()) {
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
} else {
@ -69,9 +69,7 @@ public class CameraActivity extends InjectingAppCompatActivity {
getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resolveInfoList) {
grantUriPermission(
resolveInfo.activityInfo.packageName,
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
resolveInfo.activityInfo.packageName, shared, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
}

@ -2,11 +2,13 @@ package org.tasks.files;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import com.google.common.base.Strings;
import com.nononsenseapps.filepicker.FilePickerActivity;
import com.nononsenseapps.filepicker.Utils;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
@ -67,7 +69,8 @@ public class FileExplore extends InjectingAppCompatActivity {
if (requestCode == REQUEST_PICKER) {
if (resultCode == Activity.RESULT_OK) {
Intent intent = new Intent();
intent.setData(data.getData());
File file = Utils.getFileForUri(data.getData());
intent.setData(Uri.fromFile(file));
setResult(Activity.RESULT_OK, intent);
}
finish();

@ -56,9 +56,7 @@ public class FileHelper {
} else {
Intent intent = new Intent(activity, FileExplore.class);
if (initial != null) {
intent.putExtra(
FileExplore.EXTRA_START_PATH,
new File(initial.getPath()));
intent.putExtra(FileExplore.EXTRA_START_PATH, initial.getPath());
}
return intent;
}
@ -78,9 +76,7 @@ public class FileHelper {
Intent intent = new Intent(activity, FileExplore.class);
intent.putExtra(FileExplore.EXTRA_DIRECTORY_MODE, true);
if (initial != null) {
intent.putExtra(
FileExplore.EXTRA_START_PATH,
new File(initial.getPath()));
intent.putExtra(FileExplore.EXTRA_START_PATH, initial.getPath());
}
activity.startActivityForResult(intent, rc);
}

@ -0,0 +1,6 @@
package org.tasks.files;
import androidx.core.content.FileProvider;
public class NNFileProvider extends FileProvider {
}

@ -418,7 +418,7 @@ public class Preferences {
if (atLeastKitKat()) {
return DocumentFile.fromFile(context.getExternalCacheDir()).getUri();
} else {
return Uri.fromFile(context.getCacheDir());
return Uri.fromFile(context.getExternalCacheDir());
}
}

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<root-path
name="root"
<external-path
name="external"
path="." />
<cache-path
name="cache"
<external-cache-path
name="external_cache"
path="." />
</paths>
Loading…
Cancel
Save