Skip to content

Read Android settings #794

@jace

Description

@jace

Feature description

I'd like to read Android settings from within Termux. For instance, to determine user-assigned device name, one of these adb shell commands is likely to work (revise_device_name is where my OnePlus phone keeps the user-specified device name):

adb shell settings get global revise_device_name
adb shell settings get secure bluetooth_name
adb shell settings get global device_name

Termux:API doesn't seem to have any way to invoke android.provider.Settings.Global.getString. Calling settings from the Termux CLI fails with "failure calling service settings". Wrapping stdin/out (or using cmd settings, hat tip) causes another error about missing permission android.permission.INTERACT_ACROSS_USERS, even if --user <uid> is supplied (also raised in termux/termux-app#3718 and termux/termux-app#4543)

Am I missing an obvious way to do this? It'll be nice if Termux-API provides an interface for reading settings to get around the broken OS-provided CLI tools.

Reference implementation

import android.provider.Settings;

String userDeviceName = Settings.Global.getString(getContentResolver(), "revise_device_name");
if(userDeviceName == null)
    userDeviceName = Settings.Secure.getString(getContentResolver(), "bluetooth_name");
if(userDeviceName == null)
    userDeviceName = Settings.Global.getString(getContentResolver(), Settings.Global.DEVICE_NAME);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions