那么如果想在sdk中使用这个 类要如果作呢–可以使用反射 的方法,代码如下:
public final int compare(ApplicationInfo a, ApplicationInfo b) {
ComponentName aName = a.intent.getComponent();
ComponentName bName = b.intent.getComponent();
int aLaunchCount,bLaunchCount;
long aUseTime,bUseTime;
int result = 0;
try {
//获得ServiceManager类
Class<?> ServiceManager = Class
.forName(“android.os.ServiceManager”);
//获得ServiceManager的getService方法
Method getService = ServiceManager.getMethod(“getService”, java.lang.String.class);
//调用getService获取RemoteService
Object oRemoteService = getService.invoke(null, “usagestats”);
//获得IUsageStats.Stub类
Class<?> cStub = Class
.forName(“com.android.internal.app.IUsageStats$Stub”);
//获得asInterface方法
Method asInterface = cStub.getMethod(“asInterface”, android.os.IBinder.class);