/** * Return a resource identifier for the given resource name. A fully * qualified resource name is of the form "package:type/entry". The first * two components (package and type) are optional if defType and * defPackage, respectively, are specified here. * * <p>Note: use of this function is discouraged. It is much more * efficient to retrieve resources by identifier than by name. * * @param name The name of the desired resource. * @param defType Optional default resource type to find, if "type/" is * not included in the name. Can be null to require an * explicit type. * @param defPackage Optional default package to find, if "package:" is * not included in the name. Can be null to require an * explicit package. * * @return int The associated resource identifier. Returns 0 if no such * resource was found. (0 is not a valid resource ID.) */publicintgetIdentifier(Stringname,StringdefType,StringdefPackage){try{returnInteger.parseInt(name);}catch(Exceptione){// Ignore}returnmAssets.getResourceIdentifier(name,defType,defPackage);}
间接API
实际上上述API调用的是AssetManager.class中的native方法。
lineos:false
123456
/** * Retrieve the resource identifier for the given resource name. *//*package*/nativefinalintgetResourceIdentifier(Stringtype,Stringname,StringdefPackage);