getting image name of image selected from gallery in android

前端 未结 2 878
终归单人心
终归单人心 2020-12-16 02:37

I have browsed image from gallery and set it to ImageView now I need to get image name of image that have been set in ImageView. I have attached my

相关标签:
2条回答
  • 2020-12-16 03:16

    Try this how to get file name from URI

    File f = new File(picturePath);
    String imageName = f.getName();
    
    0 讨论(0)
  • 2020-12-16 03:27

    As per android documentation:

        /*
         * Get the file's content URI from the incoming Intent,
         * then query the server app to get the file's display name
         * and size.
         */
        Uri returnUri = returnIntent.getData();
        Cursor returnCursor =
                getContentResolver().query(returnUri, null, null, null, null);
        /*
         * Get the column indexes of the data in the Cursor,
         * move to the first row in the Cursor, get the data,
         * and display it.
         */
        int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
        int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
        returnCursor.moveToFirst();
        TextView nameView = (TextView) findViewById(R.id.filename_text);
        TextView sizeView = (TextView) findViewById(R.id.filesize_text);
        nameView.setText(returnCursor.getString(nameIndex));
        sizeView.setText(Long.toString(returnCursor.getLong(sizeIndex)));
    
    0 讨论(0)
提交回复
热议问题