One of the challenges developing applications for Android is fragmentation. To make things worse, different forks like Amazon's Fire OS and CyanogenMod have significant user base to ignore. These forks despite being different have some similarities with AOSP and in some cases is good enough to run applications without any platform specific change. Anyways, there are times when application developers would want to verify if a platform resource is available in a device running either a CTS compatible version of Android or otherwise.
The hard way of doing this would be extract system files from the device, decompile and find out if a platform resource is available. Fortunately, Android offers a helper API to check for a platform resource.
getResource().getIdentifier("name", "resource_type", "package_name")
name is the exact name of the resource. A drawable resource name shouldn't include the extensions like png. resource_type is the type of the resource, drawable. package_name for platform resource is android. getIdentifier returns 0 if a resource isn't found.
So look for vp_connected.png resource,
getResources().getIdentifier( "vp_connected", "drawable", "android" );
The hard way of doing this would be extract system files from the device, decompile and find out if a platform resource is available. Fortunately, Android offers a helper API to check for a platform resource.
getResource().getIdentifier("name", "resource_type", "package_name")
name is the exact name of the resource. A drawable resource name shouldn't include the extensions like png. resource_type is the type of the resource, drawable. package_name for platform resource is android. getIdentifier returns 0 if a resource isn't found.
So look for vp_connected.png resource,
getResources().getIdentifier( "vp_connected", "drawable", "android" );
No comments:
Post a Comment