3

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

Nirav Dangi
  • 3,607
  • 4
  • 49
  • 60

1 Answers1

8

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.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
  • A follow up question would be: if the "Unknown sources" permission cannot be changed in code without admin access, is it possible to display the security settings to the user from code and let the user change it manually before returning to the app, as it's the case with GPS or WiFi settings? – MSquare May 10 '13 at 11:32
  • 3
    I found the answer to my question: :-) ----> startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS)); – MSquare May 10 '13 at 15:45