Skip to content

Commit c285137

Browse files
committed
Fix file permissions issues
1 parent 5b65541 commit c285137

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
</intent-filter>
2323
</activity>
2424

25+
<provider
26+
android:name="android.support.v4.content.FileProvider"
27+
android:authorities="${applicationId}"
28+
android:exported="false"
29+
android:grantUriPermissions="true">
30+
<meta-data
31+
android:name="android.support.FILE_PROVIDER_PATHS"
32+
android:resource="@xml/paths"/>
33+
</provider>
34+
2535
</application>
2636

2737
</manifest>

app/src/main/java/com/tananaev/logcat/MainActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.os.AsyncTask;
2424
import android.os.Bundle;
2525
import android.preference.PreferenceManager;
26+
import android.support.v4.content.FileProvider;
2627
import android.support.v7.app.AlertDialog;
2728
import android.support.v7.app.AppCompatActivity;
2829
import android.support.v7.widget.DefaultItemAnimator;
@@ -182,11 +183,12 @@ private Intent getShareIntent() {
182183
Log.w(TAG, e);
183184
}
184185

185-
Uri uri = Uri.fromFile(new File(getExternalCacheDir() + TEMP_FILE));
186+
Uri uri = FileProvider.getUriForFile(this, getPackageName(), file);
186187

187188
Intent intent = new Intent(Intent.ACTION_SEND);
188-
intent.setType("text/plain");
189+
intent.setType("text/*");
189190
intent.putExtra(Intent.EXTRA_STREAM, uri);
191+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
190192
return intent;
191193
}
192194

app/src/main/res/xml/paths.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<paths>
3+
<external-cache-path name="share_path" path="." />
4+
</paths>

0 commit comments

Comments
 (0)