Use a fileprovider to open videos in external apps

Slightly adjusted version of #322
crowdin
Floens 7 years ago
parent 6e9e7f9659
commit 8d53bd762c
  1. 12
      Clover/app/src/main/AndroidManifest.xml
  2. 36
      Clover/app/src/main/java/org/floens/chan/core/cache/FileCacheProvider.java
  3. 7
      Clover/app/src/main/java/org/floens/chan/core/di/NetModule.java
  4. 17
      Clover/app/src/main/java/org/floens/chan/ui/view/MultiImageView.java
  5. 12
      Clover/app/src/main/res/xml/file_paths.xml

@ -95,6 +95,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</receiver>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="org.floens.chan.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>

@ -0,0 +1,36 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* This program 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 org.floens.chan.core.cache;
import android.content.Context;
import android.net.Uri;
import android.support.v4.content.FileProvider;
import org.floens.chan.utils.AndroidUtils;
import java.io.File;
public class FileCacheProvider {
// Same as the one defined in the manifest.
private static final String AUTHORITY = "org.floens.chan.fileprovider";
public static Uri getUriForFile(File file) {
Context applicationContext = AndroidUtils.getAppContext();
return FileProvider.getUriForFile(applicationContext, AUTHORITY, file);
}
}

@ -37,6 +37,11 @@ public class NetModule {
}
private File getCacheDir(Context applicationContext) {
return applicationContext.getExternalCacheDir() != null ? applicationContext.getExternalCacheDir() : applicationContext.getCacheDir();
// See also res/xml/filepaths.xml for the fileprovider.
if (applicationContext.getExternalCacheDir() != null) {
return applicationContext.getExternalCacheDir();
} else {
return applicationContext.getCacheDir();
}
}
}

@ -22,9 +22,7 @@ import android.content.ContextWrapper;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.StrictMode;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
@ -40,9 +38,10 @@ import com.android.volley.toolbox.ImageLoader.ImageContainer;
import com.davemorrissey.labs.subscaleview.ImageSource;
import org.floens.chan.R;
import org.floens.chan.core.cache.FileCacheListener;
import org.floens.chan.core.cache.FileCache;
import org.floens.chan.core.cache.FileCacheDownloader;
import org.floens.chan.core.cache.FileCacheListener;
import org.floens.chan.core.cache.FileCacheProvider;
import org.floens.chan.core.model.PostImage;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.utils.AndroidUtils;
@ -386,16 +385,10 @@ public class MultiImageView extends FrameLayout implements View.OnClickListener
private void setVideoFile(final File file) {
if (ChanSettings.videoOpenExternal.get()) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "video/*");
{
StrictMode.VmPolicy vmPolicy = StrictMode.getVmPolicy();
StrictMode.setVmPolicy(StrictMode.VmPolicy.LAX);
intent.setDataAndType(FileCacheProvider.getUriForFile(file), "video/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
AndroidUtils.openIntent(intent);
StrictMode.setVmPolicy(vmPolicy);
}
AndroidUtils.openIntent(intent);
onModeLoaded(Mode.MOVIE, videoView);
} else {

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!-- Corresponds to the file path chosen in the NetModule.getCacheDir method -->
<cache-path
name="fc"
path="filecache/" />
<external-cache-path
name="exfc"
path="filecache/" />
</paths>
Loading…
Cancel
Save