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.

Can't share image from application with custom native module.

See original GitHub issue

I have made custom native module for React Native that’s need to share images from path /data/user/0/com.instagramscheduler/files/downloaded.jpg (that is my application) and to be clear file exists in that folder.

But the problem is that it is not sharing, when I share to Instagram it says that it is unable to load file. I have checked and uri.toString() == "file:///data/user/0/com.instagramscheduler/files/downloaded.jpg"

My React Native custom share method:

public void share() {
    // Create the new Intent using the 'Send' action.
    Intent share = new Intent(Intent.ACTION_SEND);

    // Set the MIME type
    share.setType("image/jpeg");
    share.setPackage("com.instagram.android");

    // Create the URI from the media
    File media = new File("/data/user/0/com.instagramscheduler/files/downloaded.jpg");
    Uri uri = Uri.fromFile(media);

    // Add the URI to the Intent.
    share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    share.putExtra(Intent.EXTRA_STREAM, uri);

    // Broadcast the Intent.
    activity.startActivity(Intent.createChooser(share, "Share To"));
}

Here is my manifest if it helps:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.instagramscheduler">

<uses-permission android:name="android.permission.INTERNET" />

<application
  android:allowBackup="true"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:theme="@style/AppTheme">
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>

Here is logcat if needed (starting from when share dialog open till it fails to share on Instagram): https://gist.github.com/Azael05x/f706925668ce9b8dd9970a81ed23e979

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
grabboucommented, Apr 25, 2016

Don’t need to hurry, I like impersonating bot here and there haha

1reaction
satya164commented, Apr 24, 2016

@grabbou Yeah, it’s not even adding the label 😦

cc @bestander

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trouble requiring image module in React Native
Since React Native release 0.14 the handling of images has been normalized for iOS and Android and is now different. I could not...
Read more >
Sharing content in React Native apps using React Native Share
Provide your users with the chance to share content across their social networks with the React Native Share package.
Read more >
Add custom native code - Expo Documentation
Learn how to start using custom native code in your app by switching from Expo Go to development builds in the Getting Started...
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 >
An In-Depth Guide to Using React Native Image Picker
Start by creating a new React Native app. Open a terminal window and execute the following command. I am going to use npx...
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