Skip to content

Commit

Permalink
Merge pull request #715 from onlydave/master
Browse files Browse the repository at this point in the history
Fix android.os.FileUriExposedException #714
  • Loading branch information
EddyVerbruggen committed Jan 6, 2017
2 parents 518887e + 0fd9ea1 commit c045445
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plugin.xml
Expand Up @@ -61,7 +61,14 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest/application">
<provider android:authorities="com.socialsharing.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />
</provider>
</config-file>

<source-file src="src/android/nl/xservices/plugins/SocialSharing.java" target-dir="src/nl/xservices/plugins"/>
<source-file src="src/android/res/xml/sharing_paths.xml" target-dir="res/xml"/>
</platform>

<!-- wp8 -->
Expand Down
3 changes: 3 additions & 0 deletions src/android/nl/xservices/plugins/SocialSharing.java
Expand Up @@ -34,6 +34,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.support.v4.content.FileProvider;

public class SocialSharing extends CordovaPlugin {

private static final String ACTION_AVAILABLE_EVENT = "available";
Expand Down Expand Up @@ -244,6 +246,7 @@ public void run() {
Uri fileUri = null;
for (int i = 0; i < files.length(); i++) {
fileUri = getFileUriAndSetType(sendIntent, dir, files.getString(i), subject, i);
fileUri = FileProvider.getUriForFile(webView.getContext(), "com.socialsharing.provider", new File(fileUri.getPath()));
if (fileUri != null) {
fileUris.add(fileUri);
}
Expand Down
3 changes: 3 additions & 0 deletions src/android/res/xml/sharing_paths.xml
@@ -0,0 +1,3 @@
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="socialsharing_downloads" path="socialsharing-downloads/" />
</paths>

0 comments on commit c045445

Please sign in to comment.