How to set settings programatically

viljemto

Member
Licensed User
Longtime User
Hi!

I would like to set some of settings od phone/device programatically.

As far as I could get, was getting this flags, that needs to be changed:
0x18404000
0x18004080
0x18005001

I am doing this in correct way or am I missing something?

Second...
0x18004080,"java.lang.int"... I know that this is wrong. Can you please advise me how to change it?

B4X:
Dim obj1 As Reflector
'obj1.Target = obj1.GetActivity
obj1.Target = obj1.GetMostCurrent(ActivityName)
obj1.Target = obj1.RunMethod("getWindow")


obj1.RunMethod2("addFlags",0x18004080,"java.lang.int")    
'obj1.RunMethod2("clearFlags",0x18004080,"java.lang.int")

Thank you!
 

viljemto

Member
Licensed User
Longtime User
I am trying to set system settings. Do I have to open that windows/dialog first? What to put in ActivityName?

With this code: screen goes blank and java.lang.NullPointerException occurs. :confused:
 
Upvote 0

viljemto

Member
Licensed User
Longtime User
Among other... HTC has Home dialing menu "com.android.htcdialer/.HomeDialingActivity"
 

Attachments

  • 2013-05-09_10-58-11.jpg
    2013-05-09_10-58-11.jpg
    54.5 KB · Views: 397
Upvote 0

viljemto

Member
Licensed User
Longtime User
No, I have just show you where are these settings located.

I want to change these values without this window.
 
Upvote 0

viljemto

Member
Licensed User
Longtime User
I am trying to figure this out. I focused on trying to set Auto-rotate screen that.

On this page the solution is for Java:
button - Set Auto-Rotate Enabled/Disabled Android - Stack Overflow

B4X:
android.provider.Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
android.provider.Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1);

Can this be translated for B4A? I am looking to set several setting. I can not find which numbers to run in RunMethod2 "addFlags".


If I change Auto-rotate manually, this is shown in logs:

HTC Desire S (Android 2.3.5)
I/ActivityManager( 1375): Displayed com.android.settings/.DisplaySettings: +316ms
V/WindowManager( 1375): Finished animation in AppWindowToken{40d44aa0 token=HistoryRecord{40c412c8 com.android.settings/.DisplaySettings}} @ 36438177
D/SensorService( 1375): enable: get sensor name = BMA150 3-axis Accelerometer
D/Sensors ( 1375): Enable akm: en = 1
D/Sensors ( 1375): mEnabled = 0x0
D/Sensors ( 1375): After modify mEnabled = 0x1
D/WindowManager( 1375): mAccelerometerDefault=0, accelerometerDefault=1
D/SensorService( 1375): SensorDevice::activate--: handle = 0x0, enabled = 0x1
D/SensorService( 1375): enable: sensor->activate return value = 0x0
D/SensorService( 1375): enable: calling mActiveSensors.add(handle, rec) = (0x0, 0xf73d00)
D/SensorService( 1375): enable: mActiveConnections.indexOf(connection) = 0x0
D/SensorService( 1375): pid=1375, uid=1000

HTC One V (Android 4.0.3)
E/HtcPreferenceActivity(26261): fragmentName: com.android.settings.DisplaySettings
I/ActivityManager( 1599): Displayed com.android.settings/.SubSettings: +262ms
I/PowerManagerService-JNI( 1599): [Stability] PowerManagerService_userActivity JNI pass power key event to PowerManagerService userActivity()
D/SensorService( 1599): enable: get sensor name = BMA250 3-axis Accelerometer
D/Sensors ( 1599): Enable G-Sensor: en = 1
D/Sensors ( 1599): mEnabled = 0x1
D/HtcPowerSaver( 1599): Checking...
I/HtcPowerSaver( 1599): >> updateStatus
D/PowerManagerService( 1599): runHtcPowerSaverCheck ======================================
D/Sensors ( 1599): /data/misc/AccPrmsF.ini does not exist
D/SensorService( 1599): SensorDevice::activate--: handle = 0x0, enabled = 0x1
D/SensorService( 1599): pid=1599, uid=1000
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Here's a library class i used recently in a project:

B4X:
package uk.co.martinpearman.b4a.rotationmanager;

import android.content.ContentResolver;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@Author("Martin Pearman")
@Permissions(values = { "android.permission.WRITE_SETTINGS" })
@ShortName("RotationManager")
@Version(1.00f)
public class RotationManager {

   public final static int ACCELEROMETER_ROTATION_DISABLED = 0;
   public final static int ACCELEROMETER_ROTATION_ENABLED = 1;
   public final static int ACCELEROMETER_ROTATION_ERROR = -1;

   public static int GetAutoRotateEnabled(BA pBA) {
      ContentResolver contentResolver = pBA.context.getContentResolver();
      String name = Settings.System.ACCELEROMETER_ROTATION;
      try {
         return Settings.System.getInt(contentResolver, name);
      } catch (SettingNotFoundException e) {
         e.printStackTrace();
         pBA.setLastException(e);
      }
      return ACCELEROMETER_ROTATION_ERROR;
   }

   public static void SetAutoRotateEnabled(BA pBA, int Enabled) {
      ContentResolver contentResolver = pBA.context.getContentResolver();
      String name = Settings.System.ACCELEROMETER_ROTATION;
      Settings.System.putInt(contentResolver, name, Enabled);
   }
}

RotationManager
  • RotationManager
    Fields:
    • ACCELEROMETER_ROTATION_DISABLED As Int
    • ACCELEROMETER_ROTATION_ENABLED As Int
    • ACCELEROMETER_ROTATION_ERROR As Int
    Methods:
    • GetAutoRotateEnabled As Int
    • SetAutoRotateEnabled (Enabled As Int)
    Permissions:
    • android.permission.WRITE_SETTINGS

The library files and source are attached.

Martin.
 

Attachments

  • RotationManager_library_and_source.zip
    5 KB · Views: 422
Upvote 0

warwound

Expert
Licensed User
Longtime User
Does anybody know where are lists for custom settings for like HTC, Samsung?

I'd suggest looking on the HTC and Samsung websites - look for any development SDKs they have available.
There might be documentation included in the SDK that documents device specific settings.

Martin.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Thats the point... You are setting/changing SYSTEM-SETTINGS... So this has affects on other apps too. If you ONLY YOUR APP to be in a certain orientation then you can add

SetActivityAttribute(main,android:screenOrientation, "sensorLandscape")

in the b4a-manifest-editor. You must put a line in manifesteditor for EACH activity... In this example i posted the code for activity "Main".
this changes only affects your app. precisely it affects only the named activity(s) from your app.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
so maybe you can limit yourself. Or say in other words. Maybe you can put all Features which uses a specific orientation into on or more specific activitys... With the code above you can select which activitys you want to set to landscape for example....

Example:
Act Main: Normal behaviour is to change orientation if user change it... Like any other app
Act specialfeaturesinlandscapp: all landscape features here. This activity get the code i posted...
Act somethingother: Normal....
 
Upvote 0
Top