So basically I'm building an app and one of those features is to be able to sync up the date time with a value from a database.
(The application is signed - and from what I have read, the SET_TIME permission is "signatureOrSystem" locked, therefore we should be able to access it)
I've got the permission required inside of the AndroidManifest.xml
```
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SET_TIME" />
<uses-permission android:name="android.permission.SET_TIME_ZONE" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
```
And I've also got permission request code sorted (I may be using the wrong request method/class)
```
if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.SetTime) != Permission.Granted)
{
if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.SetTime))
ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.SetTime }, 0);
else
ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.SetTime }, 0);
}
```
I've also added some code to ensure that the signature is attached to the debugger
```
var _context = Android.App.Application.Context;
foreach (Android.Content.PM.Signature signature in _context.PackageManager.GetPackageInfo(_context.PackageName, PackageInfoFlags.Signatures).Signatures)
{
using (SHA1Managed sha1 = new SHA1Managed())
{
var hash = sha1.ComputeHash(signature.ToByteArray());
var sb = new StringBuilder(hash.Length * 2);
foreach (byte b in hash)
{
sb.Append(b.ToString("X2"));
}
System.Diagnostics.Debug.WriteLine(sb.ToString());
}
}
```
However, I don't seem to be given access to the permission.
Which one signature comes up, which is what is expected. However, upon running through my set time button code:
```
Button _btn = FindViewById<Button>(Resource.Id.btnSetTime);
_btn.Click += (sender, e) =>
{
DateTime _time = DateTime.Now;
Calendar c = Calendar.GetInstance(new Java.Util.Locale("it-IT"));
c.Set(_time.Year, _time.Month, _time.Day, _time.Hour + 1, _time.Minute, _time.Second);
AlarmManager am = (AlarmManager)this.GetSystemService(AlarmService);
am.SetTime(c.TimeInMillis);
};
```
I am getting the error: Java.Lang.SecurityException: 'setTime: Neither user 10517 nor current process has android.permission.SET_TIME.'
I am wondering if anyone knows why this may be happening and any way to fix this? Or if its possible at all?
Android Version: 9.0 SDK Version: 28