get Real Path From URL - Android java.net

Android examples for java.net:URL

Description

get Real Path From URL

Demo Code

import android.app.Activity;
import android.content.Context;
import android.content.CursorLoader;
import android.database.Cursor;
import android.graphics.Rect;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public class Main{

    public static String getRealPathFromURL(Context mContext, String Url) {
        Uri uri = Uri.parse(Url);/*from   w  w w . j  a  v a 2  s.com*/
        return getRealPathFromURI(mContext, uri);
    }
    public static String getRealPathFromURI(Context mContext, Uri contentUri) {
        String[] proj = { MediaStore.Images.Media.DATA };
        CursorLoader loader = new CursorLoader(mContext, contentUri, proj,
                null, null, null);
        Cursor cursor = loader.loadInBackground();
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }

}

Related Tutorials