Mri*_*lla 8 java android cyanogenmod
库存Cyanogenmod ROM支持烘焙的配置文件,虽然我不确定这是否是默认Android功能的一部分,但我想知道是否有可能获得当前所选配置文件的名称.
我无法找到任何关于此的开发者文档.
(假设Android SDK不支持此功能,超级用户应用可以实现此功能吗?)
谢谢
通过一些CM源我跋涉,我找到了ProfileManager的源代码.这些方法是公开的,所以我想我不需要去Java反射的兔子洞...但是为了使用这些类,我需要一些Cyanogenmod JAR来构建.
知道了。一点丑陋的反射,瞧。这些类是ProfileManager和Profile
Object o = getSystemService("profile");
try {
Class<?> ProfileManager = Class.forName("android.app.ProfileManager");
Class<?> Profile = Class.forName("android.app.Profile");
try {
Method getActiveProfile = ProfileManager.getDeclaredMethod("getActiveProfile", null);
Method getName = Profile.getDeclaredMethod("getName", null);
try {
String strProfile = (String) getName.invoke(getActiveProfile.invoke(o));
System.out.println("Current profile is: " + strProfile);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
486 次 |
| 最近记录: |