简体   繁体   English

使用Fabric在Twitter上撰写或共享图像

[英]Tweet Compose OR Sharing Image On Twitter Using Fabric

I am following this tutorial to share tweet + image on twitter. 我正在按照本教程在Twitter上分享推文和图片。 https://docs.fabric.io/android/twitter/compose-tweets.html 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? 它可以完美地在Twitter上以成功和失败的响应共享文本,但是我却无法共享图像,有人可以指导我在这里犯什么错误吗?

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. 注意:当我从应用程序的可绘制文件夹共享图像时,它会上传,但是我必须从Internet下载图像,然后将其保存在内部存储中。

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. 图像Uri应该是本地文件的文件Uri(即file://absolute_path方案)。 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. 尝试使用absolutepath检索图像路径,这也是另一种设置Twittercard的选项。

https://dev.twitter.com/cards/types/app https://dev.twitter.com/cards/types/app

After doing some research i found: 经过一些研究,我发现:

  • when you are saving data on internal storage from your app and try to pickup inside same app it will work. 当您从应用程序将数据保存到内部存储中并尝试在同一应用程序中提取数据时,它将起作用。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM