2016-05-16 87 views
1

您好我嘗試使用共享對話框使用意圖與下面的代碼。我想同時分享圖片和文字。但我得到eror: Failed to insert image java.io.FileNotFoundException: No such file or directory在Android中使用意圖分享圖像中的圖像

我的代碼如下,我做錯了什麼。代碼位於片段類中。

Bitmap image = bmResized; 

String pathOfBmp = Images.Media.insertImage(getActivity().getContentResolver(), image, "twitter_image.jpg", null); 
Uri bmpUri = Uri.parse(pathOfBmp); 

Intent tweetIntent = new Intent(Intent.ACTION_SEND); 
tweetIntent.setAction(Intent.ACTION_SEND); 
tweetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
tweetIntent.putExtra(Intent.EXTRA_TEXT, "here is the tweet text"); 

tweetIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); 
tweetIntent.setType("image/jpeg"); 

startActivity(Intent.createChooser(tweetIntent, "Share this via")); 
+0

哪裏是圖像文件?它是在Assets或drawablle還是文件系統? –

+0

我嘗試使用圖像視圖中的圖像。我將圖像從圖像庫上傳到ima​​geView,然後將圖像視圖中的圖像轉換爲位圖。 – saner

回答

-1

試試這個:

Drawable mDrawable = mImageView.getDrawable(); 
Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap(); 

String path = MediaStore.Images.Media.insertImage(getContentResolver(), mBitmap, "Image Description", null); 
Uri uri = Uri.parse(path); 

Intent tweetIntent = new Intent(Intent.ACTION_SEND); 
tweetIntent.setType("image/jpeg"); 
tweetIntent.putExtra(Intent.EXTRA_STREAM, uri); 
startActivity(Intent.createChooser(tweetIntent, "Share this via")); 
+0

謝謝shridutt,但仍然收到錯誤:無法插入圖像java.io.FileNotFoundException:沒有這樣的文件或目錄在android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146) – saner