title: How to select and crop an image in android?
body: <p>Hey, I am currently working on a live wallpaper and I allow the user to select an image which will go behind my effects. </p>
  
  <p>Currently I have:</p>
  
  <pre><code>Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
              i.putExtra("crop", "true");
              startActivityForResult(i, 1);
  </code></pre>
  
  <p>And slightly under that:</p>
  
  <pre><code>@Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1)
          if (resultCode == Activity.RESULT_OK) {
            Uri selectedImage = data.getData();
            Log.d("IMAGE SEL", "" + selectedImage);
            // TODO Do something with the select image URI
            SharedPreferences customSharedPreference = getSharedPreferences("imagePref", Activity.MODE_PRIVATE);
            SharedPreferences.Editor editor = customSharedPreference.edit();
            Log.d("HO", "" + selectedImage);
            editor.putString("imagePref", getRealPathFromURI(selectedImage));
            Log.d("IMAGE SEL", getRealPathFromURI(selectedImage));
            editor.commit();
          } 
      }
  </code></pre>
  
  <p>When my code is ran, Logcat tells me that selectedImage is null. If I comment out the </p>
  
  <pre><code>i.putExtra("crop", "true"):
  </code></pre>
  
  <p>Logcat does not give me the null pointer exception, and I am able to do what I want with the image. So, what is the problem here? Does any one have any idea how I can fix this? Thanks, for your time.</p>