title: How to share xml layout using Intent.ACTION_SEND
body: <p>I was searching everywhere, but can't found solution...</p>
  
  <p>I have two xml layouts for share.
  I have inflated and assigned to the views correctly.</p>
  
  <pre><code>shareLayout = LayoutInflater.from(getApplicationContext()).inflate(R.layout.share_every_for_self_game_layout, null);
      contentView = (LinearLayout) shareLayout.findViewById(R.id.share_container_layout_id);
  </code></pre>
  
  <p>Problem is that the shared image is always empty.</p>
  
  <p>Here is my code</p>
  
  <pre><code>private void shareResultToFacebook(){
      try {
          Bitmap bitmap = getBitmapFromView(contentView);
  
          Intent shareIntent = new Intent();
          shareIntent.setAction(Intent.ACTION_SEND);
          shareIntent.putExtra(Intent.EXTRA_STREAM, getImageUri(this, bitmap));
          shareIntent.setType("image/jpeg");
          startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
  
      }catch (Exception e){
          e.getMessage();
      }
  
  }
  
  //create bitmap from view and returns it
  private Bitmap getBitmapFromView(View view) {
      try {
  
          view.setDrawingCacheEnabled(true);
  
          view.buildDrawingCache();
          //Define a bitmap with the same size as the view
          Bitmap returnedBitmap = Bitmap.createBitmap(800, 600, Bitmap.Config.ARGB_8888);
          //Bind a canvas to it
          Canvas canvas = new Canvas(returnedBitmap);
          //Get the view's background
          Drawable bgDrawable = view.getBackground();
          if (bgDrawable != null) {
              //has background drawable, then draw it on the canvas
              bgDrawable.draw(canvas);
          } else {
              //does not have background drawable, then draw white background on the canvas
              canvas.drawColor(Color.WHITE);
          }
          // draw the view on the canvas
          view.draw(canvas);
          //return the bitmap
          return returnedBitmap;
      }catch (Exception e){
          Global.logError("getBitmapFromView", e);
      }
      return null;
  }
  
  
  public Uri getImageUri(Context inContext, Bitmap inImage) {
      try {
          ByteArrayOutputStream bytes = new ByteArrayOutputStream();
          inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
          String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(),
                  inImage, "", "");
          return Uri.parse(path);
      }catch (Exception e){
          e.getMessage();
      }
      return null;
  }
  </code></pre>