2017-02-14 24 views
0

我已經在我的項目可繪製,我已宣佈爲獨立的資源陣列將drawables作爲緩存保存在本地存儲中,然後讀取它們以獲取Share_Intent?

public Integer[] mThumbIds = { 
     R.drawable.ic_bl1, 
     R.drawable.ic_bl2, 
     R.drawable.ic_bl3, 
     R.drawable.ic_bl4, 
     R.drawable.ic_bl5, 
     R.drawable.ic_ca1, 
     R.drawable.ic_ca2, 
     R.drawable.ic_ch} 

我想他們都保存在Android(不是SD卡)的本地存儲的臨時文件夾,以便以後可以檢索它們並通過份額intent.I送他們有意向的份額代碼完成

Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
      sharingIntent.setType("image/*"); 
      sharingIntent.putExtra(Intent.EXTRA_STREAM, path); 
     // sharingIntent.setPackage("com.facebook.orca"); 
      sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      Intent chooserIntent = Intent.createChooser(sharingIntent, "Send Via"); 
      chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      sContext.startActivity(chooserIntent); 
     // sContext.startActivity(sharingIntent); 

     } 
    }); 

我需要通過特定文件的URI來發送,最好的方式得到它是通過節省本地存儲圖像和然後在那裏檢索Uri.I知道如何將單個圖像保存在緩存中,然後檢索它。

我無法弄清楚如何在本地存儲的特定文件夾中保存可繪製的列表,然後在那裏檢索Uris以便在共享意圖中使用。

+0

可以存儲在'BASE64'格式圖像中'SharedPreferences' –

+0

也就是說,你可以得到最糟糕的建議。 – greenapps

回答

0

您可以使用此代碼。 但添加讀取和寫入存儲權限。

public void onClick(View view) { 
    Intent shareIntent = new Intent(); 
    shareIntent.setAction(Intent.ACTION_SEND); 
    shareIntent.setType("image/png"); 
    ImageView imageView = (ImageView) view; 

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

    String path = MediaStore.Images.Media.insertImage(mContext.getContentResolver(), mBitmap, "Image Description", null); 
    Uri uri = Uri.parse(path); 
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri); 
    startActivity(Intent.createChooser(shareIntent, "Share Content!!")); 

} 
+0

太棒了!謝謝。+ 1爲一個驚人的答案。是否有一種方法,我只能選擇特定的應用程序,將出現在選擇器對話框?或者更好的我可以得到當前打開的應用程序像一個信使自動選擇,當我使用shareIntent.setAction Intent.ACTION_SEND)? – enemy123

+0

是的特定的Facebook和WhatsApp的和其他社交媒體應用程序,但你需要設置組件,並嘗試找出包名稱。它一定會幫助你!祝你好運:) –

相關問題