I am following this tutorial to share tweet + image on twitter. https://docs.fabric.io/android/twitter/compose-tweets.html
Its working perfectly to share text on twitter with success and failure response but i am not able to share image, any one guide me what mistake i am doing here?
Note: when i share image from drawable folder of app it uploads, but i have to download image from Internet and then save it on internal storage.
My commented code below of explains clearly that image is being saved on internal storage as i tested it.
public void composetweet()
{
File myDir = getFilesDir();
File savedImage = new File(myDir + "/text/","test.jpg");
/* if(savedImage.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(savedImage.getAbsolutePath());
ImageView myTestImage = (ImageView) findViewById(R.id.myimageview);
myTestImage.setImageBitmap(myBitmap);
}*/
Uri myImageUri = Uri.fromFile(savedImage);
Intent intent = new TweetComposer.Builder(this)
.text("just setting up my Fabric.")
.image(myImageUri)
.createIntent();
startActivityForResult(intent, TWEET_COMPOSER_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == TWEET_COMPOSER_REQUEST_CODE) {
if(resultCode == Activity.RESULT_OK) {
// onTwitterSuccess();
} else if(resultCode == Activity.RESULT_CANCELED) {
// onTwitterCancel();
}
}
}
I have also tried:
Uri myImageUri = Uri.fromFile(savedImage);
TweetComposer.Builder builder = new TweetComposer.Builder(this)
.text("just setting up my Fabric.")
.image(myImageUri);
builder.show();
But no luck.
Any ideas?
The image Uri should be a file Uri (ie file://absolute_path
scheme) to a local file. For example:
File myImageFile = new File("/path/to/image");
Uri myImageUri = Uri.fromFile(myImageFile);
try to retrive image path with absolutepath also ther is one other option setting Twittercard.
After doing some research i found:
But if you want to share that file created from your app in another app, internal storage will not give you permissions.
Hence i followed this solution to make that work:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mobitsolutions.socialmediashare.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/pathfile"/>
</provider>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.