Android: Change Device language automatically without device restart - android

I can change device language using following adb command:
adb shell setprop persist.sys.language fr;setprop persist.sys.country CA;stop;sleep 5;start
This command will restart device after changing device language. But is it possible to change devices language without restart device?

If you're working in a testing context, you could use the fastlane screengrab tool for changing the locale of your device directly.
I myself was looking for a possibility to change the locale of the device from ADB, but failed finding one. In the end I implemented a similar approach tp screengrab. There seems to be no easy way of changing the locale on the phone. Only triggering a configuration change directly through a BroadcastReceiver makes it work. It's called DevSet and after setting everything up a more or less simple call to ADB will change the locale (on all devices I've tested so far):
adb shell am broadcast -n dev.set/.locale --es l {locale}

Related

Programmatically accessing the KNOX counter

How can you access the KNOX counter programmatically from the android SDK?
I would like my app to check the value to try and ascertain if it is running on a samsung phone that has been rooted.
I just decompiled KNOX Status. It looks like all the app is doing is getting the system property ro.boot.warranty_bit. I'm not sure if this still works and I don't have a Samsung at the moment to test.
In terminal run:
adb shell getprop ro.boot.warranty_bit
If the result is 0, then the warranty should be valid. You can use this class to get the system property in an Android app.

Android programmatically change language on rooted phone

I know that there are a few question already answered on this topic but i have a more specific problem.
I have tried to implement Android - change device system locale programmatically , with no success (simply it doesn't change the language, don't know if it's my implementation that faults...).
Searching i've found Change Device language via ADB, that is:
os.writeBytes("setprop persist.sys.language en; setprop persist.sys.country en; stop; sleep 5; start" + "\n");
and the same with
os.writeBytes("setprop persist.sys.language it; setprop persist.sys.country it; setprop ctl.restart zygote" + "\n")
that's work pretty well, apart from the fact that it does restart the phone (it doesn't reboot it, but it's a kind of restart).
I know that the "problem" is with the stop; sleep; start part, but keep them out return a change but not effective: system locale has been changed, but the effect will be shown only after phone reboot (i.e.: after reboot, language is changed).
It is really annoying to force the restart of the phone just because of changing the language; i know for sure that it is possible to make the changes effective (the default settings app does it), and i think (i'm not sure) that after making the language change a kind of intent is fired and all the apps check for the new language to show...
Does someone know how i could reach such a result?
I have a rooted phone so i have no problem with the permission stuff :)
thanks in advance!

Running shell commands on the click of a button

I wish to reset an android device programmatically using :
adb shell
recovery --wipe_data
1. What is the easiest way to do this ?
2. Will it require root/superuser access ?
For running shell commands you can use Runtime class. For more information check the documentation
For example:
Runtime.getRuntime().exec("commands_here");

Automatically forward port on start?

I need to forward a port on an android emulator, right now I had to type the command every time:
adb forward tcp:23946 tcp:23946
Is there any way to make this automatic? I tried to replace adb with a script but that command won't work until the device is up and running.
Any ideas?
Based on this answer (which I've tested and works, though it wasn't for a scenario like this one), you could simply write a script that waits until the emulator is booted.
Something like (pseudocode, don't know which platform you're on) :)
emulator #emulator-name
while ('adb shell getprop init.svc.bootanim' == "running") sleep(10s)
adb forward tcp:23946 tcp:23946

Can I use adb to change the default launcher program?

I set one of the program as default launcher program and default setting program so I cannot change the default programs now, can I change the default programs from android-sdk\android-sdk\platform-tools\adb.exe or remote shell.
How can I do that?
And can I remove the defaults of program in Java code?
For system apps you can't uninstall, use pm disable as in
adb shell pm disable com.android.launcher
you can remove (Uninstall) the default program you set using ADB by doing this :
adb uninstall app.package ..... //for example (com.example.homeapp)
If you don't want to remove the app .. here is a quick hack to do it:
adb shell
am start -a android.intent.action.MAIN
That way you will have a picker with all apps on your devices that listens to Main Action
Choose any home screen app you want . then go to settings and set it as default.
adb shell cmd package set-home-activity "package/activity"
adb reboot
The key is adb. Once you know the package name of the app you wish to clear data for, try:
adb shell pm clear package.name.of.app
It'll clear all data for the app, but I don't know of a way to only clear the defaults.
You can check and change the default sms app by using adb shell settings get secure sms_default_application and then use adb shell settings put secure sms_default_application <package name>. I'm not sure about the other default apps, but it's just a matter of finding it with adb shell settings list <secure/system/global>

Categories

Resources