gamemn02 / Settings-Database-Provider

An android package with only a content resolver work as bridge between android settings database provider and your app
Apache License 2.0
47 stars 2 forks source link

How to use it in another app? #8

Open pascua28 opened 6 months ago

pascua28 commented 6 months ago

So I've written an app but ever since updating to Android 14, I can't write to a setting anymore. Settings.System.putInt(context.getContentResolver(), "adaptive_fast_charging", 1); used to work on Android 13. I tried the Settings Database Editor without this app and it failed. But after installing this app, it successfully set the setting I need. My question is how do I use it as a provider for my app? Thanks

gamemn02 commented 5 months ago

You mean even after installing the package successfully in Android 14 without error? if not, try following solution from @lmore377: "The app needs to be installed thru adb with adb install --bypass-low-target-sdk-block filename.apk"

pascua28 commented 4 months ago

You mean even after installing the package successfully in Android 14 without error? if not, try following solution from @lmore377: "The app needs to be installed thru adb with adb install --bypass-low-target-sdk-block filename.apk"

What I mean is how to use this as a provider for an app that I wrote? Sorry, I don't fully understand contentproviders

gamemn02 commented 4 months ago

Settings.System.putInt() don't allow you to change the uri (may be it is possible by creating a contentresolver?), so instead I used:

val contentValues = ContentValues(2)
contentValues.put("name", key)
contentValues.put("value", value)
contentResolver.insert(Uri.parse("content://settings/system"), contentValues)

(in kotlin) If i want to change to using the provider package, then i set the uri "content://settings/system" to "content://com.netvor.provider.SettingsDatabaseProvider/system"

you may also need to add following permissions to AndroidManifest:

<uses-permission android:name="com.netvor.settings.tables.provider.permission.SETTINGS_TABLES_PROVIDER" />
<queries>
    <provider android:authorities="com.netvor.provider.SettingsDatabaseProvider" />
</queries>
pascua28 commented 4 months ago

Settings.System.putInt() don't allow you to change the uri (may be it is possible by creating a contentresolver?), so instead I used:

val contentValues = ContentValues(2)
contentValues.put("name", key)
contentValues.put("value", value)
contentResolver.insert(Uri.parse("content://settings/system"), contentValues)

(in kotlin) If i want to change to using the provider package, then i set the uri "content://settings/system" to "content://com.netvor.provider.SettingsDatabaseProvider/system"

you may also need to add following permissions to AndroidManifest:

<uses-permission android:name="com.netvor.settings.tables.provider.permission.SETTINGS_TABLES_PROVIDER" />
<queries>
    <provider android:authorities="com.netvor.provider.SettingsDatabaseProvider" />
</queries>

I realized that target sdk version needs to be set to 22 for it to work. Though simply setting the target sdk for my app works, it's a bit inconvenient to install an update so I opted out to using your app. Thank you

gamemn02 commented 4 months ago

the problem with setting the target sdk to 22 is that you won't be able to publish on Google Play, but notice that even the provider package is inconvenient to install on Android 14 and you need adb for that. and also it could be a bit challenging to convince users that the provider package is totally safe to install. and also notice that if you want to modify secure and global tabels, you need to grant corresponding permission (WRITE_SECURE_SETTINGS) to the provider package instead of app