Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9298215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:16:02+00:00 2026-06-18T22:16:02+00:00

I am using this intent to open a chooser to pick up a file:

  • 0

I am using this intent to open a chooser to pick up a file:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setDataAndType(Uri.parse(getExternalFilesDir(null).toString()), "*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
Intent chooser = Intent.createChooser(intent, "Choose File");
startActivityForResult(chooser, FILE_SELECT);

I don’t fully understand it, but it works. I copied it from some example in the web
The result is an uri, but I find the processing of the uri, also copied from the example, too cumbersome

if(uri != null) {
    if("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = {"_data"};
        Cursor cursor = null;
        try {
            cursor = context.getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if(cursor.moveToFirst()) {
                return cursor.getString(column_index);
            }
        }
        catch (Exception e) {}
    } else if("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }
}

Is this the simplest way to let the user pick a file and get its path?
Why do I need to check if the uri is “content”? I just want to open a text or zipped file the user chose in the intent.
Can I ignore the “content” check, just assume “file” and simply use uri.getPath() ?

Edit I: Is there a way to force choosing with uri scheme “file”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:16:04+00:00Added an answer on June 18, 2026 at 10:16 pm

    Yes. This is correct. You are basically starting an intent to get access to the native app. which in this case is the file system. The next would be a part of the onActivityResultData() which would then use the uri on the intent and get the contents of the file that has been selected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to open a new activity using this code: myListView.setOnItemClickListener(new OnItemClickListener() { @Override
Hi I'm using this to open up the native android camera application Intent camera
I am using camera Intent to open the camera: Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
I am opening android camera using intent like this : Intent cameraIntent = new
I am using an broadcast receiver for Intent.ACTION_BATTERY_CHANGED. Rate at which I receive this
Using this to load the json var jsonParsed = JSON.parse(localStorage.getItem('test')); Using this to save
Using this C# application pick a start and ending date range, that SAP will
This is a really strange problem... last week I was using this intent filter
from my application i'm trying to open another one, using this code: package com.copag.lanceappli;
I have edited the code by using setOnClick pending intent, and this code works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.