开发者

Why do not work in android setBacklightBrightness(int)

i'am try to change brightness from my widget with reflected method but this code failen on moment setBacklightBrightness.invoke(power, new Object[]{Brightness}); and write invoke error. Please help!

public static void LoadIPowerClass(Context context)
{   
    try{
    //Load classes and objects

    Object power;
    Context fContext = context;
    Class <?> ServiceManager = Class.forName("android.os.ServiceManager");
    Class <?> Stub = Class.forName("android开发者_高级运维.os.IPowerManager$Stub");


    Method getService = ServiceManager.getMethod("getService", new Class[] {String.class});
    //Method asInterface = GetStub.getMethod("asInterface", new Class[] {IBinder.class});//of this class?
    Method asInterface = Stub.getMethod("asInterface", new Class[] {IBinder.class});    //of this class?
    IBinder iBinder = (IBinder) getService.invoke(null, new Object[] {Context.POWER_SERVICE});//
    power = asInterface.invoke(null,iBinder);//or call constructor Stub?//

    Method setBacklightBrightness = power.getClass().getMethod("setBacklightBrightness", new Class[]{int.class}); 

    int Brightness = 5;

    setBacklightBrightness.invoke(power, new Object[]{Brightness});//HERE Failen

    Log.i(TAG, "Load internal IPower classes Ok");               
    }catch(InvocationTargetException e){                     //HERE catch!!!!

....


Thanks you very very much for your code, it works VERY WELL !

Regarding your exception, you're probably missing the DEVICE_POWER permission in your app. In order to get this permission, you must use a root uid. Add android:sharedUserId="android.uid.system" inside the <manifest> tag and SIGN your application using the phone's OEM key (private key used by constructor, or the private key of your development platform).

Regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜