InvoiceActivity class using reflections to get resources class
first its bad idea and you doing it wrong way :)
why u not using provided context which starts activity to obtain resources class name ?
why not use ? context.getApplicationContext() and use in
public static int getResIdByName(Context context, String name, String type) {
return context.getResources().getIdentifier(name, type, context.getPackageName());
}
you should address also some other issues:
- multidex / used classloader could not be aware of multiple dex files
if you need use reflection try:
// use space name not android application id :) - see my last words
Class<?> aClass = classLoader.loadClass(javaPackageName +".R$id");
-
differences between package/applicationId and java package for class name R as
getPackageName()
returns the flavor-specific "package" (applicationId) instead of what you defined in the app's manifest (package field).- be aware of that that
now my app can't use your api as packageName.R doesn't exist in my app :)
you have two choices to correct this:
- iterate over all classes until you find expected resource or
- get proper package name / space name
you should mention also that lib requires
<uses-permission android:name="android.permission.NFC"/>
and for api>23 that should be gathered at run-time !