I would like to toggle resolution and density of my phone using my application (don't want to use ADB).
- When I use 
Runtime.getRuntime().exec("wm density 220")it doesn't work on AVD nor at my rooted phone Galaxy S8 with Custom ROM. - When I use 
Runtime.getRuntime().exec("wm size 1080x1920")it changes resolution on my Galaxy S8 but not on AVD. 
I granted android.permission.WRITE_SECURE_SETTINGS to all my devices.
What I tried already:
- With super user privileges granted via
(Runtime.getRuntime().exec("su"), I still can't change density with my app - I can change density and size (resolution) with adb commands on any device
 - I can change size(resolution) with application Tasker (this application has android.permission.WRITE_SECURE_SETTINGS) but it isn't possible to change density. Change density in Tasker is possible only with root.
 - Application Second Screen (has also android.permission.WRITE_SECURE_SETTINGS and is possible to download source code on Github) could change resolution and density on my AVD and on my Galaxy S8 without ROOT
 - With application Terminal Emulator I could change size and density only with ROOT
 - Application Second Screen and also it is mentioned on this site: http://nomone.com/2016/10/11/modifying-android-system-settings/ using code "Settings.Global.putString" this should fix my problem, but I don't know how to use it. Could you please help me?
 
//Part of the code used from http://nomone.com/ and is also used in app
//Second Screen, there they don't use Runtime.getRuntime.exec("...")
Settings.Global.putString(
mContext.getContentResolver(),
Settings.Global.DISPLAY_SIZE_FORCED, width + "," + height);
//this is part of the code with Runtime.getRuntime
Process process = Runtime.getRuntime().exec("wm density 220");
process.waitFor();
