I founded this class with the function: setBackgroundDataSetting, on kiwidoc.com.
I just need this function for my application.
But like the site say's: "This class is not part of the public API."
. I can not use it in my IDE.
So i googled around looking for this iConne开发者_运维百科ctivityManager, but i just can not find it only more documents.
Should i just forget about it ( I don't want too ) or is there a way to get this class?
Thanks,
DeDanny.
Should i just forget about it ( I don't want to ) or is there a way to get this class?
A standard SDK application cannot hold the permission needed to change the background data setting. Hence, whether you can get to this class or not is probably immaterial.
You can get the instance of iConnectivityManager via ConnectivityManager see below how :-
final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Class conmanClass conmanClass = Class.forName(conman.getClass().getName());
final java.lang.reflect.Field iConnectivityManagerField = conmanClass.getDeclaredField("mService");
iConnectivityManagerField.setAccessible(true);
final Object iConnectivityManager = iConnectivityManagerField.get(conman);
final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName());
Now, you can call any method or field from this class, actually this class no longer exist but this is the backdoor way of accessing this class, for eg. you want to access the any method from this class say setMobileDataEnabledMethod(),
so
final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
similarly any other field,
final java.lang.reflect.Field iConnectivityManagerField = iConnectivityManagerClass.getDeclaredField("xyz");
i hope this will clear query leave your comments for more...
精彩评论