how to get file name from URI

后端 未结 8 596
花落未央
花落未央 2020-12-16 15:46

Hello I am develop video player with android gallery. I receive URI from gallry. and I need to display video title, when play video. so if content has not title meta data. I

相关标签:
8条回答
  • 2020-12-16 16:21

    If the uri is a content provider uri, this is how you should retrieve file info.

            Cursor cursor = getContentResolver().query(uri, 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);
            cursor.moveToFirst();
            nameView.setText(cursor.getString(nameIndex));
    

    https://developer.android.com/training/secure-file-sharing/retrieve-info.html

    0 讨论(0)
  • 2020-12-16 16:22

    Here i am giving you a sample code which will upload image from gallery

    To extract filename/Imagename,Do the following

    File f = new File(selectedPath);
    System.out.println("Image name is   ::" + f.getName());//get name of file
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case 1:
    if (resultCode == YourActivity.RESULT_OK) {
    Uri selectedImageUri = data.getData();
    String selectedPath = getPath(selectedImageUri);
    File f = new File(selectedPath);
    System.out.println("Image name is   ::" + f.getName());//get name of file
    }
    }
    

    Hope this will help

    0 讨论(0)
提交回复
热议问题