Example usage for android.net Uri getPath

List of usage examples for android.net Uri getPath

Introduction

In this page you can find the example usage for android.net Uri getPath.

Prototype

@Nullable
public abstract String getPath();

Source Link

Document

Gets the decoded path.

Usage

From source file:com.facebook.stetho.inspector.ChromeDiscoveryHandler.java

@Override
protected void handleSecured(HttpRequest request, HttpResponse response, HttpContext context)
        throws HttpException, IOException {
    Uri uri = Uri.parse(request.getRequestLine().getUri());
    String path = uri.getPath();
    try {//from w  w w.  j a  va2 s.  c  om
        if (PATH_VERSION.equals(path)) {
            handleVersion(response);
        } else if (PATH_PAGE_LIST.equals(path)) {
            handlePageList(response);
        } else if (PATH_ACTIVATE.equals(path)) {
            handleActivate(response);
        } else {
            response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
            response.setReasonPhrase("Not Implemented");
            response.setEntity(new StringEntity("No support for " + uri.getPath()));
        }
    } catch (JSONException e) {
        response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        response.setReasonPhrase("Internal Server Error");
        response.setEntity(new StringEntity(e.toString(), Utf8Charset.NAME));
    }
}

From source file:Main.java

/**
 * Get the real file path from URI registered in media store 
 * @param contentUri URI registered in media store 
 *//*  www  .  jav  a2  s.  com*/
public static String getRealPathFromURI(Activity activity, Uri contentUri) {

    String releaseNumber = Build.VERSION.RELEASE;

    if (releaseNumber != null) {
        /* ICS, JB Version */
        if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') {
            // URI from Gallery(MediaStore)
            String[] proj = { MediaStore.Images.Media.DATA };
            String strFileName = "";
            CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null);
            Cursor cursor = cursorLoader.loadInBackground();
            if (cursor != null) {
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToFirst();
                if (cursor.getCount() > 0)
                    strFileName = cursor.getString(column_index);

                cursor.close();
            }
            // URI from Others(Dropbox, etc.) 
            if (strFileName == null || strFileName.isEmpty()) {
                if (contentUri.getScheme().compareTo("file") == 0)
                    strFileName = contentUri.getPath();
            }
            return strFileName;
        }
        /* GB Version */
        else if (releaseNumber.startsWith("2.3")) {
            // URI from Gallery(MediaStore)
            String[] proj = { MediaStore.Images.Media.DATA };
            String strFileName = "";
            Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null);
            if (cursor != null) {
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

                cursor.moveToFirst();
                if (cursor.getCount() > 0)
                    strFileName = cursor.getString(column_index);

                cursor.close();
            }
            // URI from Others(Dropbox, etc.) 
            if (strFileName == null || strFileName.isEmpty()) {
                if (contentUri.getScheme().compareTo("file") == 0)
                    strFileName = contentUri.getPath();
            }
            return strFileName;
        }
    }

    //---------------------
    // Undefined Version
    //---------------------
    /* GB, ICS Common */
    String[] proj = { MediaStore.Images.Media.DATA };
    String strFileName = "";
    Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null);
    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

        // Use the Cursor manager in ICS         
        activity.startManagingCursor(cursor);

        cursor.moveToFirst();
        if (cursor.getCount() > 0)
            strFileName = cursor.getString(column_index);

        //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version)
        activity.stopManagingCursor(cursor);
    }
    return strFileName;
}

From source file:Main.java

/**
 * Get the real file path from URI registered in media store 
 * @param contentUri URI registered in media store 
 */// www.  j  a v  a2  s  .  c o  m
@SuppressWarnings("deprecation")
public static String getRealPathFromURI(Activity activity, Uri contentUri) {

    String releaseNumber = Build.VERSION.RELEASE;

    if (releaseNumber != null) {
        /* ICS, JB Version */
        if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') {
            // URI from Gallery(MediaStore)
            String[] proj = { MediaStore.Images.Media.DATA };
            String strFileName = "";
            CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null);
            Cursor cursor = cursorLoader.loadInBackground();
            if (cursor != null) {
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToFirst();
                if (cursor.getCount() > 0)
                    strFileName = cursor.getString(column_index);

                cursor.close();
            }
            // URI from Others(Dropbox, etc.) 
            if (strFileName == null || strFileName.isEmpty()) {
                if (contentUri.getScheme().compareTo("file") == 0)
                    strFileName = contentUri.getPath();
            }
            return strFileName;
        }
        /* GB Version */
        else if (releaseNumber.startsWith("2.3")) {
            // URI from Gallery(MediaStore)
            String[] proj = { MediaStore.Images.Media.DATA };
            String strFileName = "";
            Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null);
            if (cursor != null) {
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

                cursor.moveToFirst();
                if (cursor.getCount() > 0)
                    strFileName = cursor.getString(column_index);

                cursor.close();
            }
            // URI from Others(Dropbox, etc.) 
            if (strFileName == null || strFileName.isEmpty()) {
                if (contentUri.getScheme().compareTo("file") == 0)
                    strFileName = contentUri.getPath();
            }
            return strFileName;
        }
    }

    //---------------------
    // Undefined Version
    //---------------------
    /* GB, ICS Common */
    String[] proj = { MediaStore.Images.Media.DATA };
    String strFileName = "";
    Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null);
    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

        // Use the Cursor manager in ICS         
        activity.startManagingCursor(cursor);

        cursor.moveToFirst();
        if (cursor.getCount() > 0)
            strFileName = cursor.getString(column_index);

        //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version)
        activity.stopManagingCursor(cursor);
    }
    return strFileName;
}

From source file:com.duy.pascal.ui.activities.SplashScreenActivity.java

private void handleActionView(@NonNull Intent from, @NonNull Intent to) {
    if (from.getData() == null || from.getType() == null) {
        return;/*from w w  w.  java2s .c o m*/
    }
    DLog.d(TAG, "handleActionView() called with: from = [" + from + "], to = [" + to + "]");
    if (from.getData().toString().endsWith(".pas") || from.getData().toString().endsWith(".txt")) {
        Uri uriPath = from.getData();
        DLog.d(TAG, "handleActionView: " + uriPath.getPath());
        try {
            String filePath = FileManager.getPathFromUri(this, uriPath);
            if (filePath != null) {
                to.putExtra(CompileManager.EXTRA_FILE, new File(filePath));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (from.getType().equals("text/x-pascal")) {
        Uri uri = from.getData();
        try {
            //clone file
            InputStream inputStream = getContentResolver().openInputStream(uri);
            FileManager fileManager = new FileManager(this);
            File file = fileManager.createRandomFile(this);
            fileManager.copy(inputStream, new FileOutputStream(file));

            to.putExtra(CompileManager.EXTRA_FILE, file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.smapley.vehicle.activity.SetActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try {/* w w  w .  j  a  va2s  . c  o m*/
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
            case 0:
                List<String> resultList = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
                //?
                Uri sourceUri = Uri.fromFile(new File(resultList.get(0)));
                Uri destinationUri = Uri.fromFile(new File(getCacheDir(), "SampleCropImage.jpeg"));
                UCrop.of(sourceUri, destinationUri).withAspectRatio(1, 1).withMaxResultSize(maxWidth, maxHeight)
                        .start(SetActivity.this);
                break;
            case UCrop.REQUEST_CROP:
                //
                final Uri resultUri = UCrop.getOutput(data);
                File file = new File(resultUri.getPath());
                updatePic(file);
                break;
            }

        }
    } catch (Exception e) {

    }
}

From source file:com.lugia.timetable.MasterActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        Log.d(TAG, "Non RESULT_OK received: " + resultCode);

        return;/*  w w w . j av  a  2s  . com*/
    }

    switch (requestCode) {
    case REQUEST_CODE_OPEN_FILE: {
        Uri selectedFileUri = data.getData();

        String path = selectedFileUri.getPath();

        // some file choose may need other method to get path
        if (path == null || path.equals(""))
            return;

        mFilename = path;

        break;
    }

    case REQUEST_CODE_DOWNLOAD_DATA: {
        // recreate the entire activity
        recreate();

        break;
    }
    }
}

From source file:com.dycody.android.idealnote.CategoryActivity.java

public void save(Bitmap bitmap) {
    if (bitmap == null) {
        setResult(RESULT_CANCELED);/*from  w w  w .j a  v a 2 s  . co m*/
        super.finish();
    }

    try {
        Uri uri = getIntent().getParcelableExtra(MediaStore.EXTRA_OUTPUT);
        File bitmapFile = new File(uri.getPath());
        FileOutputStream out = new FileOutputStream(bitmapFile);
        assert bitmap != null;
        bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);

        if (bitmapFile.exists()) {
            Intent localIntent = new Intent().setData(Uri.fromFile(bitmapFile));
            setResult(RESULT_OK, localIntent);
        } else {
            setResult(RESULT_CANCELED);
        }
        super.finish();

    } catch (Exception e) {
        Log.d(Constants.TAG, "Bitmap not found", e);
    }
}

From source file:com.xabber.android.data.account.WLMManager.java

@Override
public boolean isValidUri(Uri uri) {
    return WLM_SCHEME.equals(uri.getScheme()) && WLM_AUTHORITY.equals(uri.getAuthority())
            && WLM_REDIRECT_PATH.equals(uri.getPath());
}

From source file:com.zoterodroid.activity.BrowseCitations.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse_bookmarks);

    mAccountManager = AccountManager.get(this);
    mAccount = mAccountManager.getAccountsByType(Constants.ACCOUNT_TYPE)[0];
    mContext = this;

    Log.d("browse bookmarks", getIntent().getDataString());
    Uri data = getIntent().getData();
    String scheme = data.getScheme();
    String path = data.getPath();
    Log.d("path", path);
    String username = data.getQueryParameter("username");
    String tagname = data.getQueryParameter("tagname");
    String recent = data.getQueryParameter("recent");

    myself = mAccount.name.equals(username);

    ArrayList<Citation> citationList = new ArrayList<Citation>();

    if (scheme.equals("content") && path.equals("/citations") && myself) {

        try {/*from   w  w w  . j  a v a2  s. co m*/

            String[] projection = new String[] { Citation._ID, Citation.Title, Citation.Key,
                    Citation.Creator_Summary, Citation.Item_Type };
            String selection = null;
            String sortorder = null;

            selection = Citation.Account + " = '" + username + "'";

            Uri citations = Citation.CONTENT_URI;

            Cursor c = managedQuery(citations, projection, selection, null, sortorder);

            if (c.moveToFirst()) {
                int idColumn = c.getColumnIndex(Citation._ID);
                int titleColumn = c.getColumnIndex(Citation.Title);
                int keyColumn = c.getColumnIndex(Citation.Key);
                int creatorSummaryColumn = c.getColumnIndex(Citation.Creator_Summary);
                int itemTypeColumn = c.getColumnIndex(Citation.Item_Type);

                do {

                    Citation b = new Citation(c.getInt(idColumn), c.getString(titleColumn),
                            c.getString(keyColumn), c.getString(creatorSummaryColumn),
                            c.getString(itemTypeColumn));

                    citationList.add(b);

                } while (c.moveToNext());

            }

            setListAdapter(new CitationListAdapter(this, R.layout.bookmark_view, citationList));
        } catch (Exception e) {
        }

    }

    lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        }
    });

    /* Add Context-Menu listener to the ListView. */
    lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            menu.setHeaderTitle("Actions");
            if (myself) {
                menu.add(Menu.NONE, 0, Menu.NONE, "Delete");
            } else {
                menu.add(Menu.NONE, 1, Menu.NONE, "Add");
            }

        }
    });
}

From source file:cn.iterlog.imgaepicker.home.MainFragment.java

@Override
public void showChooseImage(boolean isVideo, Uri uri) {
    if (!isVideo) {
        chooseIv.setImageURI(uri);//  w  ww  .  j  a v a 2s.co  m
    } else {
        Bitmap bm = ThumbnailUtils.createVideoThumbnail(uri.getPath(), MediaStore.Images.Thumbnails.MINI_KIND);
        chooseIv.setImageBitmap(bm);
    }
}