title: Getting error : cannot resolve method getResource()
body: <p>I'm trying to share image with <code>Intent.ACTION_SEND</code> but getting this error: </p>
  
  <blockquote>
    <p>cannot resolve method getResource()</p>
  </blockquote>
  
  <p>This is the code I'm trying to share image with:</p>
  
  <pre><code>            File root = android.os.Environment.getExternalStorageDirectory();
              File dir = new File (root.getAbsolutePath() + "/myFolder");
              dir.mkdirs(); // build directory
              Random generator = new Random();
              int n = 10000;
              n = generator.nextInt(n);
              String fileName = "Image-"+ n +".jpg";
              File file = new File(dir, fileName);
              if (file.exists ()) file.delete ();
  
              try {
                  FileOutputStream outStream = new FileOutputStream(file);
                  InputStream is;
                  Bitmap bitmap;
                  is = this.getResources().openRawResource(R.drawable.image1);
                  bitmap = BitmapFactory.decodeStream(is);
                  try {
                      is.close();
                      is = null;
                  } catch (IOException e) {
                  }
                  bitmap.compress(Bitmap.CompressFormat.JPEG, 90, outStream);
                  outStream.flush();
                  outStream.close();
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              Uri outputFileUri = Uri.fromFile(file);
              Intent intent = new Intent(Intent.ACTION_SEND);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
              intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
              intent.setType("image/jpeg");
              intent.putExtra(Intent.EXTRA_STREAM, outputFileUri);
              startActivity(Intent.createChooser(intent, "Share this image via"));
  </code></pre>