Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically change the permission of installing apk from unknown source in android device

Tags:

android

apk

For allowing or preventing manually installation of apk file from sdcard we ticks/unticks the checkbox which says "Allow installation of app from unknown source".

Can we do this Programmatically by avoiding any User Interface?

Thanks,

Nirav

like image 287
Nirav Dangi Avatar asked Jan 02 '26 08:01

Nirav Dangi


1 Answers

No, not unless you're a carrier, or not unless you're on an enterprise phone that your company has admin access over.

This is part of the security model of Android, so that a user can not lose the control of his phone to a malicious application.

Here are the actual permissions you would need to do something like that:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />

You can try using those permissions, but by design they won't work unless you have root access to the device.

Within the device settings, users are able to view permissions for applications they have previously installed. Users can also turn off some functionality globally when they choose, such as disabling GPS, radio, or wi-fi.

In the event that an application attempts to use a protected feature which has not been declared in the application's manifest, the permission failure will typically result in a security exception being thrown back to the application. Protected API permission checks are enforced at the lowest possible level to prevent circumvention.

like image 145
Stephan Branczyk Avatar answered Jan 04 '26 01:01

Stephan Branczyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!