Android modifies Android system Language using the Java reflection mechanism

Source: Internet
Author: User

Private voidupdatelanguage (locale locale) {Try{Object objiactmag, objactmagnative; Class Clziactmag= Class.forName ("Android.app.IActivityManager"); Class clzactmagnative= Class.forName ("android.app.ActivityManagerNative"); Method Mtdactmagnative$getdefault= Clzactmagnative.getdeclaredmethod ("Getdefault"); //Iactivitymanager Iactmag = Activitymanagernative.getdefault ();Objiactmag =Mtdactmagnative$getdefault.invoke (clzactmagnative); //Configuration config = iactmag.getconfiguration ();Method mtdiactmag$getconfiguration = Clziactmag.getdeclaredmethod ("GetConfiguration"); Configuration Config=(Configuration) Mtdiactmag$getconfiguration.invoke (OBJIACTMAG); Config.locale=locale; //iactmag.updateconfiguration (config); //you need to declare permissions here: Android.permission.CHANGE_CONFIGURATION//onCreate () will be called again;Class[] Clzparams = {Configuration.class }; Method mtdiactmag$updateconfiguration=Clziactmag.getdeclaredmethod ("updateconfiguration", Clzparams);        Mtdiactmag$updateconfiguration.invoke (objiactmag, config); } Catch(Exception e) {e.printstacktrace (); }    }

Parameters are obtained from Local, for example: Local.english;

Before use should root system, adb shell

->su

Then # PM Grant Com.example.clickdemo Android.permission.CHANGE_CONFIGURATION manually give permission, otherwise the reflection exception will be reported

Android modifies Android system Language using the Java reflection mechanism

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.