5

I have an Android app that handles plug-ins of my specific storage device. I want to be able to show the contents of the storage device in a specific way with my Display activity when the device is mounted on the system. The problem I'm having is that on some phones the system also handles the ACTION_MEDIA_MOUNTED broadcast and then automatically brings up the Android file explorer (which takes the screen away from my app). This is what I am trying to prevent if at all possible. I am registering a broadcast receiver to listen for the ACTION_MEDIA_MOUNTED broadcast and then starting my Display activity as soon as I receive this broadcast like so:

BroadcastReceiver mediaMountedReceiver = new BroadcastReceiver()
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        Log.d("debug", "HEAR YE! HEAR YE! THE MEDIA HAS BEEN MOUNTED!");
        if (isOrderedBroadcast()) {
            abortBroadcast();
        }
        Intent i = new Intent(getApplicationContext(), Display.class);
        startActivity(i);
    }
};

...

IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
filter.addDataScheme("file");
filter.setPriority(999);
registerReceiver(mediaMountedReceiver, filter);

I receive the broadcast alright and I try to cancel it by calling abortBroadcast() but apparently ACTION_MEDIA_MOUNTED is not an ordered broadcast. Is there any way to stop propagation of this broadcast or to direct all storage mount/unmount broadcasts to my app?

If this is not possible does anyone have tips or workarounds on how to deal with this?

4

0 回答 0