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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:27:46+00:00 2026-06-12T16:27:46+00:00

I have big problems with MediaStore. I need to handle events when MediaStore is

  • 0

I have big problems with MediaStore. I need to handle events when MediaStore is changed over MTP. I already have a receiver for android.intent.action.MEDIA_SCANNER_FINISHED action, but it is useful only for Universal Mass Storage(UMS). The scanner is not launched over MTP, because the MTP changes the MediaStore database directly.

Please would you be so kind and help me how to detect this events. Thank you very much for any help!

  • 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-12T16:27:48+00:00Added an answer on June 12, 2026 at 4:27 pm

    I finally found a solution. I tried to use FileObserver but when you use it for all directories…it is quite memory consuming. So now I am using ContentObserver and it is working well:

    public static class UriObserver
    {
        private final Cursor mCursor;
        private final ContentObserver mObserver;
        private boolean mRunning = true;
    
        private class ObserverWithListener extends ContentObserver
        {
            private final OnChangeListener mListener;
    
            public ObserverWithListener(OnChangeListener listener)
            {
                super(new Handler());
    
                mListener = listener;
            }
    
            @Override
            public void onChange(boolean selfChange)
            {
                if (mRunning)
                {
                    log.d("Change triggered");
                    mListener.onChange();
                }
            }
        };
    
        public static UriObserver getInstance(ContentResolver contentResolver, Uri uri, OnChangeListener listener)
        {
            Cursor c = contentResolver.query(uri, new String[] { "*" }, null, null, null);
    
            if ((c = Dao.moveToFirst(c)) == null)
            {
                log.e("Cannot start observer for uri: " + uri);
                return null;
            }
    
            return new UriObserver(c, listener);
        }
    
        public UriObserver(Cursor c, final OnChangeListener listener)
        {
            mCursor = c;
            mObserver = new ObserverWithListener(listener);
            mCursor.registerContentObserver(mObserver);
        }
    
        public void stop()
        {
            mCursor.unregisterContentObserver(mObserver);
            Dao.closeCursor(mCursor);
            mRunning = false;
        }
    
        public interface OnChangeListener
        {
            public void onChange();
        }
    }
    

    The flag mRunning has to be there for some reason because onChange was sometimes called even if unregisterContentObserver() had been called before.

    This code I am using with Uris that I want to observe, i.e. MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, …

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

Sidebar

Related Questions

I have big problems with css buttons... My screen size is 1366x768 and their
I really have big problems with importing an extern C-Library to my existing C++-Project.
I have big problem when I am trying to deploy my app over clickonce.
i have some problems. I have one big file that provide one error with
I have big problems with stopping a service, which plays audio file. I want
I am having big problems in fetching exception details from Remote EJBs... I have
I'm having big problems doing operation with the date in Excel VBA. I have
I have big problems. I'm new on a small company and now I'm in
I have had really big problems understand the char* lately. Let's say I made
I'm having big problems while creating a simple program in C. I have the

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.