Google提供了libGoogleAnalyticsServices.jar,可以通过调用进行初始化

gaTracker = EasyTracker.getInstance(context);

在这种情况下,初始化所需的值(trackingId)从analytics.xml中读取。我想将该功能添加到我的图书馆项目中。但是读取值需要访问编译的R.class。

String s = getResources().getString(R.urls.myUrl);

如此答案中所述:
Android How to add a custom xml file in res/values and how to register the customvalues.xml with the system

有没有一种方法可以仅使用值的名称来读取值?我不能在主项目上添加依赖项。

最佳答案

我认为他们可以这样做:

String packageName = context.getPackageName();
int resId = context.getResources().getIdentifier("ga_trackingId", "string", packageName);
String val = context.getString(resId);
Log.d("String From Res", val);

10-07 12:44
查看更多