Konstantine Tirkia
Konstantine Tirkia

Reputation: 79

java.lang.SecurityException: Neither user 11029 nor current process has android.permission.SET_TIME_ZONE

I am working on an old project which sets time zone programatically, i am migrating this project to Api 28, it works without error on Kitkat device but in Api 28, SET_TIME_ZONE permission can't be granted, as i know it became system level permission and can't be available for apps.

I have added this permissions

<uses-permission android:name="android.Manifest.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.SET_TIME_ZONE"
    tools:ignore="ProtectedPermissions" />

and Activity onCreate method looks like this

int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, 2654);
} 
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.setTimeZone("Asia/Tbilisi");

and getting error on Api 28 or higher

java.lang.SecurityException: Neither user 11029 nor current process has android.permission.SET_TIME_ZONE.

I want to keep this functionality, whats your advice what should i use instead of AlarmManager.setTimeZone() method to change system time?

Upvotes: 2

Views: 1766

Answers (1)

Code Demon
Code Demon

Reputation: 1334

Prompt for timezone selection.if you need the user to select a specific zone,give a message with the instruction before opening setting activity to prompt the user.After selecting,you can then check if the system timezone is as expected and take whatever action.

startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS));

Upvotes: 1

Related Questions