Can't share image from application with custom native module.
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>
Here is logcat if needed (starting from when share dialog open till it fails to share on Instagram): https://gist.github.com/Azael05x/f706925668ce9b8dd9970a81ed23e979
@facebook-github-bot stackoverflow
I think it might have something to do with permissions, not really sure. The code itself looks similar to what I have (and to other docs, like here -> https://github.com/codepath/android_guides/wiki/Sharing-Content-with-Intents#sending-images). I believe you could get a better answer on StackOverflow from Android community as that has nothing to do with React Native itself :)
@satya164 @mkonicek did you also notice that @facebook-github-bot seems to not be closing issues properly recently?
@grabbou Yeah, it's not even adding the label :(
cc @bestander
I've marked few manually so when the bot gets back to life - we can auto-close them ( 🌟 ) . Also @bestander my cla command does not seem to work as well. I think it might be related as that is the most recent change to bot as far as I can tell.
Thanks for reporting, we will have a look
@grabbou Will look into it, thanks a lot for reporting.
Don't need to hurry, I like impersonating bot here and there haha