Skip to main content

Featured

Android studio “SDK tools directory is missing”

Following 2 possible solutions will resolve this problem :  Solution1 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:" Delete your  ~/.Android*  folders (losing all of your settings :/). Run Android Studio. It will show you a welcome wizard where it tries to download the SDK again (and fails due to my rubbish internet). Click the X on the wizard window. That will enable you to get to the normal welcome dialog. Go to Settings->Project Defaults->Project Structure and change the Android SDK location to the correct one. Solution 2 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:&quo

Code to Change Android Phone language programmatically,Android

Change Android Phone language programmatically

 





public static void change_setting_arabic(Context con) {
  try {
                        /** here add language code */
   Locale locale = new Locale("ar");

   Class amnClass = Class.forName("android.app.ActivityManagerNative");
   Object amn = null;
   Configuration config = null;

   // amn = ActivityManagerNative.getDefault();
   Method methodGetDefault = amnClass.getMethod("getDefault");
   methodGetDefault.setAccessible(true);
   amn = methodGetDefault.invoke(amnClass);

   // config = amn.getConfiguration();
   Method methodGetConfiguration = amnClass
     .getMethod("getConfiguration");
   methodGetConfiguration.setAccessible(true);
   config = (Configuration) methodGetConfiguration.invoke(amn);

   // config.userSetLocale = true;
   Class configClass = config.getClass();
   Field f = configClass.getField("userSetLocale");
   f.setBoolean(config, true);

   // set the locale to the new value
   config.locale = locale;

   // amn.updateConfiguration(config);
   Method methodUpdateConfiguration = amnClass.getMethod(
     "updateConfiguration", Configuration.class);
   methodUpdateConfiguration.setAccessible(true);
   methodUpdateConfiguration.invoke(amn, config);

  } catch (Exception e) {
   // TODO: handle exception
   Log.d("error lang change-->", "" + e.getMessage().toString());
  }
}

Comments

  1. will you Please send the full source code to my mail :(krishnapillai87@gmail.com)
    thank you

    ReplyDelete
    Replies
    1. Hi Krishna
      This complete method is the complete source code for converting the language.
      For that u can just cal this method from Activity and pass the Activity context to that method.
      Use language whatever u want in first line of the method inside try block.

      Regards,
      Pavan.

      Delete
  2. Hi pavan,Nice article .Keep it Up.I used your code,but its not working in emulator.Did you add any Strings value in the Strings.xml file.otherwise could you send the Full source code of the project.My mail id is arunroy06@yahoo.co.in

    ReplyDelete
  3. This code is for android 2.2+ and before version. Current I need code for android 4.x/5.x/6.x
    Can you provide details for above requirement?
    Thanks

    ReplyDelete
  4. Hi, Thanks for your help.
    This code is for android 2.2+, and before version. Current I need code for android 4.x/5.x/6.x
    Can you provide details for my requirement?
    Thanks

    ReplyDelete

Post a Comment