Skip to content

Commit b244e40

Browse files
thomas154maskaravivek
authored andcommitted
Fix achievements activity share option (commons-app#2416) (commons-app#2478)
* Use fileProvider instead of Uri.fromFile() * As Uri.fromFile() will not work on Android 7.0+, with a targetSdkVersion of 24 or higher, throws FileUriExposedException
1 parent 5a9cce0 commit b244e40

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
android:largeHeap="true"
3232
android:hardwareAccelerated="false"
3333
android:supportsRtl="true" >
34+
3435
<activity android:name="org.acra.CrashReportDialog"
3536
android:theme="@android:style/Theme.Dialog"
3637
android:launchMode="singleInstance"

app/src/main/java/fr/free/nrw/commons/achievements/AchievementsActivity.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.graphics.drawable.Drawable;
1010
import android.net.Uri;
1111
import android.os.Bundle;
12+
import android.support.v4.content.FileProvider;
1213
import android.support.v4.content.res.ResourcesCompat;
1314
import android.support.v7.app.AlertDialog;
1415
import android.support.v7.widget.Toolbar;
@@ -184,13 +185,15 @@ void shareScreen(Bitmap bitmap) {
184185
fOut.flush();
185186
fOut.close();
186187
file.setReadable(true, false);
188+
Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), getPackageName()+".provider", file);
189+
grantUriPermission(getPackageName(), fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
187190
final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
188191
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
189-
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
192+
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
190193
intent.setType("image/png");
191194
startActivity(Intent.createChooser(intent, "Share image via"));
192195
} catch (IOException e) {
193-
//Do Nothing
196+
e.printStackTrace();
194197
}
195198
}
196199

app/src/main/res/xml/provider_paths.xml

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<cache-path name="images" path="images/" />
44
<external-path name="Download" path="./"/>
55
<root-path name="root" path="." />
6+
<external-cache-path name="external_cache_path" path="."/>
67
</paths>

0 commit comments

Comments
 (0)