![](/img/trans.png)
[英]Android: adding image to tweet using Fabric, Twitter REST API and Retrofit
[英]Tweet Compose OR Sharing Image On Twitter Using Fabric
我正在按照本教程在Twitter上分享推文和圖片。 https://docs.fabric.io/android/twitter/compose-tweets.html
它可以完美地在Twitter上以成功和失敗的響應共享文本,但是我卻無法共享圖像,有人可以指導我在這里犯什么錯誤嗎?
注意:當我從應用程序的可繪制文件夾共享圖像時,它會上傳,但是我必須從Internet下載圖像,然后將其保存在內部存儲中。
我在下面的評論代碼中清楚地解釋了圖像在我測試時已保存在內部存儲器中。
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();
}
}
}
我也嘗試過:
Uri myImageUri = Uri.fromFile(savedImage);
TweetComposer.Builder builder = new TweetComposer.Builder(this)
.text("just setting up my Fabric.")
.image(myImageUri);
builder.show();
但是沒有運氣。
有任何想法嗎?
圖像Uri應該是本地文件的文件Uri(即file://absolute_path
方案)。 例如:
File myImageFile = new File("/path/to/image");
Uri myImageUri = Uri.fromFile(myImageFile);
嘗試使用absolutepath檢索圖像路徑,這也是另一種設置Twittercard的選項。
經過一些研究,我發現:
但是,如果您想在另一個應用程序中共享從您的應用程序創建的文件,則內部存儲不會授予您權限。
因此,我按照以下解決方案進行工作:
<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.