mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Use FileProvider instead of File URIs
This commit is contained in:
@@ -223,5 +223,15 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="android.support.v4.content.FileProvider"
|
||||||
|
android:authorities="org.isoron.uhabits"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/file_paths" />
|
||||||
|
</provider>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import java.io.*;
|
|||||||
|
|
||||||
import static android.os.Build.VERSION.*;
|
import static android.os.Build.VERSION.*;
|
||||||
import static android.os.Build.VERSION_CODES.*;
|
import static android.os.Build.VERSION_CODES.*;
|
||||||
|
import static android.support.v4.content.FileProvider.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all screens in the application.
|
* Base class for all screens in the application.
|
||||||
@@ -50,6 +51,8 @@ import static android.os.Build.VERSION_CODES.*;
|
|||||||
*/
|
*/
|
||||||
public class BaseScreen
|
public class BaseScreen
|
||||||
{
|
{
|
||||||
|
public static final int REQUEST_CREATE_DOCUMENT = 1;
|
||||||
|
|
||||||
protected BaseActivity activity;
|
protected BaseActivity activity;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -230,11 +233,14 @@ public class BaseScreen
|
|||||||
|
|
||||||
public void showSendFileScreen(@NonNull String archiveFilename)
|
public void showSendFileScreen(@NonNull String archiveFilename)
|
||||||
{
|
{
|
||||||
|
File file = new File(archiveFilename);
|
||||||
|
Uri fileUri = getUriForFile(activity, "org.isoron.uhabits", file);
|
||||||
|
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(Intent.ACTION_SEND);
|
intent.setAction(Intent.ACTION_SEND);
|
||||||
intent.setType("application/zip");
|
intent.setType("application/zip");
|
||||||
intent.putExtra(Intent.EXTRA_STREAM,
|
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
||||||
Uri.fromFile(new File(archiveFilename)));
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
activity.startActivity(intent);
|
activity.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
app/src/main/res/xml/file_paths.xml
Normal file
27
app/src/main/res/xml/file_paths.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
~
|
||||||
|
~ This file is part of Loop Habit Tracker.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker 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.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker 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/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<paths>
|
||||||
|
<files-path name="files" path="." />
|
||||||
|
<cache-path name="cache" path="." />
|
||||||
|
<external-path name="external" path="." />
|
||||||
|
<extendal-cache-path name="external-cache" path="." />
|
||||||
|
<external-files-path name="external-files" path="." />
|
||||||
|
</paths>
|
||||||
Reference in New Issue
Block a user