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

  • SEARCH
  • Home
  • 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 9219653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:09:52+00:00 2026-06-18T03:09:52+00:00

My app allows user to save files on an external SD card besides the

  • 0

My app allows user to save files on an external SD card besides the getExternalStorage() path. I understand that Android does not have notion of external SD cardas such but as we know many device manufacturers provide an extra SD card slot for the tablets/phones. And the path to this particular sdcard could be vendor dependent.

My app provides the user a preference where he/she can provide that vendor path to the SD card that’s different than the path returned by getExternalStorage().

Previously I would use following code to invoke media scanner,

  sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
  + Environment.getExternalStorageDirectory())));

But now I am wondering whether the following code might work:

  sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
  + "/someotherpath/blah/");

Would it work? I do not have such a device with an extra SD card slot to test it out, your opinion would be useful for me.

  • 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-18T03:09:54+00:00Added an answer on June 18, 2026 at 3:09 am

    I took a look in Android open source code (Android 4.1)

    There is file called /packages/providers/MediaProvider/src/com/android/providers/media/MediaScannerReceiver.java

    It has following code:

     @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Uri uri = intent.getData();
            if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
                // scan internal storage
                scan(context, MediaProvider.INTERNAL_VOLUME);
            } else {
                if (uri.getScheme().equals("file")) {
                    // handle intents related to external storage
                    String path = uri.getPath();
                    String externalStoragePath = Environment.getExternalStorageDirectory().getPath();
    
                    Log.d(TAG, "action: " + action + " path: " + path);
                    if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                        // scan whenever any volume is mounted
                        scan(context, MediaProvider.EXTERNAL_VOLUME);
                    } else if (action.equals(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE) &&
                            path != null && path.startsWith(externalStoragePath + "/")) {
                        scanFile(context, path);
                    }
                }
            }
        }
    

    As you can see it will check for ACTION_MEDIA_MOUNT (which you use) and it will call scan(). However, it will use hardcoded MediaProvier.EXTERNAL_VOLUME (instead of passed file URI).

    Answering your question, it doesn’t make sense for you to change your code. Any URI with file schema will work the same.

    However, there is a chance that vendor will modify this code.

    And one more thing. Android 4.2 introduced multiuser notion and each user has his/her own external storage. Based on this, shown code may have changed.

    Update 1

    It’s interesting. Initially, I just looked through part of MediaScannerReceiver and was under impression that it will scan only one external volume. However, after you told me that you looked through the code and asked whether it will work. I investigate a little bit further and found that it will search all mountable volumes (as you said).

    As I understand it goes through following execution path (it in kind of pseudo-java code to disregard all instantiations and so on)

    • MediaScannerReceiver.onReceive calls scan(context, MediaProvider.EXTERNAL_VOLUME);
    • MediaScannerReceiver.scan calls context.startService(
      new Intent(context, MediaScannerService.class).putExtras(args)); where args contain key/value pair “volume”=MediaProvider.EXTERNAL_VOLUME)
    • MediaScannerService.onStartCommand calls mServicehandler.sendMessage
    • MediaScannerService.ServiceHandler.handleMessage receives a message and calls equivalent of
      scan(StorageManager.getVolumePaths(),MediaProvider.EXTERNAL_VOLUME)
    • MediaScannerService.scan calls MediaScanner.scanDirectories
    • MediaScanner goes through each directory one by one

    Taking into account that “StorageManager.getVolumePaths()” should return all mountable volumes, I think you should be fine with your current code (it will scan all volumes).

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

Sidebar

Related Questions

I am creating a multimedia app that allows the user to save wallpapers and
My app allows a user to save an image to their SD card. But
I have an app that allows the user to take and save a new
I'm making an app that allows the user to create files (html) and edit
I have an app that allows users to save and open text files. Saving
For an app that allows user to login in with Facebook, and will support
I am writing an app that allows user to view the list of installed
I have a small tab on an app that allows user to lookup a
I have an app that allows the user to choose an image, at design
I have an app that allows the user to choose a picture from their

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.