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.