Pregunta

I really don't like all the MediaScanner Android system and how it is implemented, battery consumption, card not reachable, etc, so I made a directory based image viewer. I know how to disable (enable) the scanner from a console with this:

su & pm disable (enable) com.android.providers.media/com.android.providers.media.MediaScannerReceiver

Now, I want to do this from the java code of my viewer. Of course I can do a Runtime.getRuntime().exec(...), but I have some questions:

1) Is there a way of doing this without the Runtime.getRuntime().exec()?

2) How can I know if the MediaScannerReceiver is enabled or disabled? I Googled for this and I couldn't find the anwser. The MediaScannerConnection does not seem to control this. Actually, I don't know what pm does...

3) Is it possible to do this without root access?

Thanks!

¿Fue útil?

Solución

Part 2). This was the main question, and this is a solution:

    ComponentName sc = new ComponentName("com.android.providers.media", "com.android.providers.media.MediaScannerReceiver");
    int isEnabled = getPackageManager().getComponentEnabledSetting(sc);
    if (isEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { ... }

Part 1). The way would be:

ComponentName sc = new ComponentName("com.android.providers.media", "com.android.providers.media.MediaScannerReceiver");
getPackageManager().setComponentEnabledSetting(sc, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);

Problem is that this does not work (fatal error java.lang.SecurityException: Permission Denial: attempt to change component state from pid=23632, uid=10133, package uid=10081), since this is a system package. This is due to Part 3:

Part 3) Not even root access is necessary, it can't be done in java code through the API by security reasons: the API simply does not allow it. So it seems to me that Runtime.getRuntime().exec("su & pm ...") is the only way.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top