簡體   English   中英

如何為ImageView創建共享意圖?

[英]how to create a Share Intent for an ImageView?

我正在創建一個照片應用程序,用戶從庫中選擇和圖像,它顯示在應用程序中心的圖像視圖中。 我將如何為ImageView創建共享意圖?

更新共享意圖正在工作,但是,圖像無法共享,因為我無法將其保存到我選擇的路徑。 以下是我的代碼。 有幫助嗎?

public void taptoshare(View v)
    {  
        View content = findViewById(R.id.myimage);
        content.setDrawingCacheEnabled(true);
            Bitmap bitmap = content.getDrawingCache();
            File file = new File("/DCIM/Camera/image.jpg");
            try 
            {
                file.createNewFile();
                FileOutputStream ostream = new FileOutputStream(file);
                bitmap.compress(CompressFormat.JPEG, 100, ostream);
                ostream.close();
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }


        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        Uri phototUri = Uri.parse("/DCIM/Camera/image.jpg");
        shareIntent.setData(phototUri);
        shareIntent.setType("image/*");
        shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri);
        startActivity(Intent.createChooser(shareIntent, "Share Via"));

}  

}

嘗試這個

Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri phototUri = Uri.parse(path);
shareIntent.setData(photootUri);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, photootUri);
getContext().startActivity(Intent.createChooser(shareIntent, "Use this for sharing"));

請參閱以下鏈接。 這對你很有幫助。 我認為它滿足了你的要求。

http://www.technotalkative.com/android-pick-image-from-native-gallery/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM