Ryusuke Fuda's Tech Blog

Softweare Enginier about Web, iOS, Android.

Android Bitmap シェア実装

AndroidでBitmap画像をシェアする方法

  //Bitmap をてきとうに作る
      	Bitmap screenBitmap = getBitmap(viewContainer);
		        	
      	// Save this bitmap to a file.
        File cache = getApplicationContext().getExternalCacheDir();
        File sharefile = new File(cache, "toshare.png");
        try {
            FileOutputStream out = new FileOutputStream(sharefile);
            screenBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
            out.flush();
            out.close();
        } catch (IOException e) {
	 
        }
	 
        // send it out to share
        Intent share = new Intent(android.content.Intent.ACTION_SEND);
        share.setType("image/*");
        share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + sharefile));
        try {
            startActivity(Intent.createChooser(share, "Share photo"));
        } catch (Exception e) {

        }