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 7868905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:08:39+00:00 2026-06-03T01:08:39+00:00

I am writing an application that needs to detect when the SD card is

  • 0

I am writing an application that needs to detect when the SD card is mounted as a disk drive to a computer via USB or when it has been manually removed. I tried using a broadcast receiver for this purpose, but the onReceive is not getting called. My code is as follows.

IntentFilter filter2 = new IntentFilter();
        //filter2.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        filter2.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
        filter2.addAction(Intent.ACTION_MEDIA_SHARED);
        filter2.addAction(Intent.ACTION_MEDIA_REMOVED);
        filter2.addAction(Intent.ACTION_MEDIA_MOUNTED);

        registerReceiver(new CustomBroadcastReceiver(), filter2);

My broadcast receiver is as follows…

public class CustomBroadcastReceiver extends BroadcastReceiver{

    public CustomBroadcastReceiver(){

    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if(action.equals(Intent.ACTION_MEDIA_UNMOUNTED) || action.equals(Intent.ACTION_MEDIA_SHARED) || action.equals(Intent.ACTION_MEDIA_REMOVED)){
            HardwareManager.IS_MEDIA_MOUNTED = false;
        }else if(action.equals(Intent.ACTION_MEDIA_MOUNTED)){
            HardwareManager.IS_MEDIA_MOUNTED = true;
        }else if(action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)){
            HardwareManager.IN_AIRPLANE_MODE = intent.getBooleanExtra("state", false);
        }
    }

}

The onReceive method does not fire when I connect as a disk drive via USB.

What am I doing wrong ?

  • 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-03T01:08:41+00:00Added an answer on June 3, 2026 at 1:08 am

    You have to add the “file” scheme (addDataScheme(“file”)) in order for the IntentFilter to match the broadcast ACTION_MEDIA_* action intents.

    The ACTION_MEDIA_* intents have the path to the mount point in Intent.mData field (see Intent docs) but an IntentFilter with no schemes set will only match an intent if it includes no data (see IntentFilter docs).

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

Sidebar

Related Questions

I'm writing a small tray application that needs to detect the last time a
I am writing an extension for an existing application that needs to handle USB
I'm writing an application that needs to uncompress data compressed by another application (which
I am writing an iPhone application that needs to record audio from the built-in
I am writing a Facebook application that needs to post on a friend's wall
I'm writing a windows service application that needs to serialize and deserialize XML documents
I am writing a .NET WinForms application that needs to display a list of
I am writing an Adobe AIR application that needs to build in a CI
I am writing a java application that takes schema-bounded XML as input and needs
I'm writing a system that underlies programmer applications and that needs to detect 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.