「Android」IPowerManagerのshutdownインタフェースを実装するコード

Javaコード
try{
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,Context.POWER_SERVICE);
//IPowerManager.Stub取得
Class> cStub = Class.forName(“android.os.IPowerManager$Stub");
//asInterface取得
Method asInterface = cStub.getMethod(“asInterface", android.os.IBinder.class);
//asInterfaceでIPowerManagerオブジェクト取得
Object oIPowerManager = asInterface.invoke(null, oRemoteService);
//shutdown()取得
Method shutdown = oIPowerManager.getClass().getMethod(“shutdown",boolean.class,boolean.class);
//shutdown()実行
shutdown.invoke(oIPowerManager,false,true);
} catch (Exception e) {
Log.e(TAG, e.toString(), e);
}

Android

Posted by arkgame