question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android local file share doesn't share contents of file

See original GitHub issue

Steps to reproduce

  1. Attempt to share a local text file via Share.open using the local path as described in the docs, e.g. url: "file:///storage/emulated/0/test.txt"

Expected behaviour

The contents of the file should be shared to the selected app

Actual behaviour

Instead of the file contents the file url is shared to the app, e.g. if I share to Gmail the string “file:///storage/emulated/0/test.txt” is copied into the email.

Environment

  • React Native version: .55.3
  • React Native platform + platform version: Android 8.1.0

react-native-share

Version: 1.1.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
suwu150commented, Dec 11, 2018

@watchtower314 add below code add app/src/main/AndroidManifest.xml

        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:grantUriPermissions="true"
            android:exported="false">
            <meta-data
                tools:replace="android:resource"
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>

and in res/xml/filepaths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="myexternalimages" path="Download/" />
    <root-path name="root" path="" />
    <files-path
        name="files-path"
        path="." /> <!-- Used to access into application data files -->
</paths>

and path add prefix file://,so result path :file:///data/user/0/com.appName/cache/123456.pdf, it will work fine

1reaction
watchtower314commented, Dec 12, 2018

@suwu150 's solution did the trick! Although at first it seemed not to work; it caused a different error that said failed to find configured root that contains /file:/storage/emulated/0/123456.pdf but after removing the app from my device and rebuilding, it worked perfectly!

Thanks!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android local file share doesn't share contents of file #385
if I share to Gmail the string "file:///storage/emulated/0/test.txt" is copied into the email.
Read more >
Sharing a file - Android Developers
Once you have set up your app to share files using content URIs, you can respond to other apps' requests for those files....
Read more >
Share files or apps with Nearby Share - Google Support
Share files or apps with Nearby Share · On your Android device, open Files by Google Files Go . · At the top...
Read more >
Android 6: cannot share files anymore? - Stack Overflow
Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("image/*"); Uri uri = Uri.fromFile(new File(mFilename)); shareIntent.
Read more >
11 easy ways to transfer files from an Android to a PC or Mac
You may need a different one if your phone has the newer USB Type-C-to-Type-C cable and your desktop or laptop doesn't have a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found