2013-01-10 151 views
1

我試圖共享使用共享意圖保存到內部存儲的圖像文件。 我意圖圖像文件不顯示後。Android共享意圖共享圖像不存在

我用下面的代碼來保存圖像文件

try { 
    FileOutputStream fos = openFileOutput("twitterimage.jpg", Context.MODE_PRIVATE); 
    // Writing the bitmap to the output stream 
    bikeBm.compress(Bitmap.CompressFormat.JPEG, 100, fos); 
    fos.close(); 
} catch (Exception e) { 
    Log.e("saveToInternalStorage()", e.getMessage()); 
} 

//意圖代碼

File internalFile = getFileStreamPath("twitterimage.jpg"); 
Uri uri = Uri.fromFile(internalFile); 

Intent shareIntent = new Intent(); 
shareIntent.setAction(Intent.ACTION_SEND); 
shareIntent.putExtra(Intent.EXTRA_STREAM,new File(uri)); 
shareIntent.setType("image/jpeg"); 
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
startActivity(Intent.createChooser(shareIntent, "send")); 

當我使用上述「URI」檢查文件所有腦幹,在圖像文件中的存在 內部存儲但檢查文件使用

String file = "data/data/com.bike.app/twitterimage.jpg"; 
File f = new File(file); 

顯示我的文件不存在exis噸。

請幫我解決這個問題。

+0

看吧http://stackoverflow.com/questions/13917495/sharing-on-twitter-and-facebook-via-android-app/13917710#13917710 –

回答

2

如果我正在尋找你想分享圖像之間的應用程序。你的問題是你在編寫文件時使用了Context.MODE_PRIVATE,所以其他應用程序無法訪問這個文件。

要共享圖像,您可以使用MediaProvider來限制對您的媒體或簡單使用Context.MODE_WORLD_READABLE的訪問,但該文件將是公共可讀的。

希望幫助

+0

謝謝你的回覆。我嘗試了Context.MODE_PUBLIC,但它不存在。所以我使用MODE_WORLD_READABLE來保存圖像,然後得到了工作!thanx你給我的提示。 – Hassy31

+0

對不起,我有編輯我的帖子的權利 – Antoine