Obtain absolute path of a txt file

2

I need to get the absolute path in Android of a .txt file after a chooser file

I have this Code:

private String myPath;
Uri datos;  
private static final int COD_SELECCIONA_TXTART = 10;  

public void elegirArchivo(View vista){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/*");
startActivityForResult(intent.createChooser(intent, "Elige una aplicación"),COD_SELECCIONA_TXTART);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode){
        case COD_SELECCIONA_TXTART:
            Uri datos = data.getData();
            Toast.makeText(this, String.valueOf(datos), Toast.LENGTH_LONG).show();
            break;
    }  

I need to show the absolute path in Toast but I get something like:

  

content: //com.mobisystems.fileman.RemoteFiles/ZmlsZTov ....

But I need to get something like this:

  

/storage/emulated/folder/folder/folder/filename.txt

How do I do it?

    
asked by Humberto Arciniega 26.09.2018 в 15:40
source

1 answer

0

Hello, you can test if it works like this, inside the OnActivityResult

  if (requestCode == COD_SELECCIONA_TXTART && resultCode == RESULT_OK){
        datos = data.getData();
        Toast.makeText(this, datos+"", Toast.LENGTH_LONG).show();
    }
    
answered by 26.09.2018 в 18:25