Fix achievements activity share option (#2416) (#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
This commit is contained in:
Blesson Thomas 2019-02-27 01:53:56 +05:30 committed by Vivek Maskara
parent 5a9cce0f79
commit b244e403c2
3 changed files with 7 additions and 2 deletions

View file

@ -31,6 +31,7 @@
android:largeHeap="true" android:largeHeap="true"
android:hardwareAccelerated="false" android:hardwareAccelerated="false"
android:supportsRtl="true" > android:supportsRtl="true" >
<activity android:name="org.acra.CrashReportDialog" <activity android:name="org.acra.CrashReportDialog"
android:theme="@android:style/Theme.Dialog" android:theme="@android:style/Theme.Dialog"
android:launchMode="singleInstance" android:launchMode="singleInstance"

View file

@ -9,6 +9,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.FileProvider;
import android.support.v4.content.res.ResourcesCompat; import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -184,13 +185,15 @@ public class AchievementsActivity extends NavigationBaseActivity {
fOut.flush(); fOut.flush();
fOut.close(); fOut.close();
file.setReadable(true, false); file.setReadable(true, false);
Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), getPackageName()+".provider", file);
grantUriPermission(getPackageName(), fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
final Intent intent = new Intent(android.content.Intent.ACTION_SEND); final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); intent.putExtra(Intent.EXTRA_STREAM, fileUri);
intent.setType("image/png"); intent.setType("image/png");
startActivity(Intent.createChooser(intent, "Share image via")); startActivity(Intent.createChooser(intent, "Share image via"));
} catch (IOException e) { } catch (IOException e) {
//Do Nothing e.printStackTrace();
} }
} }

View file

@ -3,4 +3,5 @@
<cache-path name="images" path="images/" /> <cache-path name="images" path="images/" />
<external-path name="Download" path="./"/> <external-path name="Download" path="./"/>
<root-path name="root" path="." /> <root-path name="root" path="." />
<external-cache-path name="external_cache_path" path="."/>
</paths> </paths>