title: move image from one folder to another in android sdcard
body: <p>In my project I'm selecting image from the gallery and want to move it from gallery to some other folder in my sdcard .... so far I have done selecting the image and the path of the image is also got... now I have to move that image from that folder....
  thanks in advance</p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
      ImageView iv;
      Button load,cp;
      TextView tv,tvpath;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          iv = (ImageView)findViewById(R.id.imageView);
  
          tv = (TextView)findViewById(R.id.textView);
          tvpath = (TextView)findViewById(R.id.textView2);
  
          load = (Button)findViewById(R.id.button);
          cp = (Button)findViewById(R.id.button2);
  
          load.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                  i.setType("image/*");
                  startActivityForResult(i, 1);
              }
          });
  
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  
          super.onActivityResult(requestCode, resultCode, data);
  
          if(requestCode== 1 &amp;&amp; resultCode == RESULT_OK &amp;&amp; data != null){
              String realpath;
              if (Build.VERSION.SDK_INT &lt; 11){
  
                  realpath = RealPathUtil.getRealPathFromURI_BelowAPI11(this,data.getData());
  
              }else if (Build.VERSION.SDK_INT &lt; 19){
  
                  realpath = RealPathUtil.getRealPathFromURI_BelowAPI11to18(this, data.getData());
  
              }else{
  
                  realpath = RealPathUtil.getRealPathFromURI_API19(this, data.getData());
              }
  
              settext(Build.VERSION.SDK_INT,data.getData().getPath(),realpath);
              changepath(realpath);
  
  
  
             /* Uri pickimage = data.getData();
  
              String[] filepath = {MediaStore.Images.Media.DATA};
  
  
              Cursor cursor = getContentResolver().query(pickimage,filepath,null,null,null);
              cursor.moveToFirst();
  
              String imgpath = cursor.getString(cursor.getColumnIndex(filepath[0]));
  
              iv.setImageBitmap(BitmapFactory.decodeFile(imgpath));
  
              cursor.close();
  
              Toast.makeText(getApplicationContext(),filepath[0],Toast.LENGTH_SHORT).show();
              */
          }
  
      }
  //tried to chage the path here
  
      private void changepath(String realpath) {
          File rp = new File(realpath);
          File cp = new File("/mnt/sdcard/myapp/");
  
          rp.renameTo(cp);
          String s = rp.getAbsolutePath();
  
  
          Toast.makeText(getApplicationContext(),"new path is:"+s,Toast.LENGTH_LONG).show();
  
      }
  
      private void settext(int sdkInt, String path, String realpath) {
              this.tv.setText("uri path :"+path);
          this.tvpath.setText("Real path :"+realpath);
  
          Uri uri = Uri.fromFile(new File(realpath));
  
          iv.setImageURI(uri);
      }
  
      }
  **RealPathUtil**
  
      public class RealPathUtil {
      public static String getRealPathFromURI_BelowAPI11(Context context, Uri contentUri) {
          String[] proj = { MediaStore.Images.Media.DATA };
          Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
          int column_index
                  = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
          cursor.moveToFirst();
          return cursor.getString(column_index);
      }
  
  
      public static String getRealPathFromURI_BelowAPI11to18(Context context, Uri contentUri) {
          String[] proj = { MediaStore.Images.Media.DATA };
          String result = null;
  
          CursorLoader cursorLoader = new CursorLoader(
                  context,
                  contentUri, proj, null, null, null);
          Cursor cursor = cursorLoader.loadInBackground();
  
          if(cursor != null){
              int column_index =
                      cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
              cursor.moveToFirst();
              result = cursor.getString(column_index);
          }
          return result;
      }
  
      public static String getRealPathFromURI_API19(Context context, Uri data) {
  
          String filepath = "";
  
          String wholeID = DocumentsContract.getDocumentId(data);
  
          String[] column = {MediaStore.Images.Media.DATA};
  
          String sel = MediaStore.Images.Media._ID + "=?";
  
          String id = wholeID.split(":")[1];
          Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,column,sel,new String[]{ id },null);
  
          int columnIndex = cursor.getColumnIndex(column[0]);
          if (cursor.moveToFirst()){
              filepath = cursor.getString(columnIndex);
  
          }
          cursor.close();
          return filepath;
      }
  }
  </code></pre>