I am developing an Android app for Jellybean, KitKat and Lollipop and several different devices.
At the beginning of project, I used the Jellybean API library with target API 'anroid-18' using 'Samsung galaxy note 2014 edition'. A few months later, the OS of the device started upgrading to KitKat OS, so I changed the library to 'android-19' in which version number is 4.4.2.
I have new device named Galaxy S tab 2 now.
I have the three versions and two devices now and my default API is 4.4.2.
The problem occurred when capturing pictures using the app:
if (Build.VERSION.SDK_INT >= AlopexBuild.VERSION_SUPPORT.KITKAT) {
Intent mediaScanIntent
= new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.parse("file://"+ path);
mediaScanIntent.setData(contentUri);
sendBroadcast(mediaScanIntent);
} else {
sendBroadcast(
new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ path)));
}
The following code has no problem in Jellybean:
Intent mediaScanIntent
= new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.parse("file://"+ path);
mediaScanIntent.setData(contentUri);
sendBroadcast(mediaScanIntent);
Why is this happening?
Jellybean OS + Kitkat API = Failed
Kitkat OS + Kitkat API = OK
Lollipop OS + KitKat API = OK
Problematic code is
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ path)));
According to the wiki articles references for each OS when releasing the new KitKat and Lolipop OS and moving from Jellybean they changed to a new kind of runtime enviroment. The code only compatible in this new enviroment, you'll need to try a different method for other enviroments like Jellybean. See here and here