Subscription preference

Notification emails are sent to your Samsung account email address.

* Email :



Android Sleep Time

Forums View
Started by Newbie ansh**** , 140 Seed Apr 18, 2017 07:58 Replies : 2 View : 284922 Likes : 0
Here , I want to know thta why I'm getting issue while fetching sleep hours. The error is:

 java.lang.IllegalArgumentException - Not permitted property ( is used

I'm trying same way as we got steps count by mentioning in manifest and activity and a reported class but I'm not getting sleep hours. The sleep count reporter class as:


public class SleepCountReporter {

    private final HealthDataStore mStore;
    private final HealthResultHolder.ResultListener<HealthDataResolver.ReadResult> mListener = new HealthResultHolder.ResultListener<HealthDataResolver.ReadResult>() {
        public void onResult(HealthDataResolver.ReadResult result) {
            int count = 0;
            Cursor c = null;

            try {
                c = result.getResultCursor();
                if (c != null) {
                    while (c.moveToNext()) {
                        count += c.getInt(c.getColumnIndex(HealthConstants.Sleep.HEALTH_DATA_TYPE));
            } finally {
                if (c != null) {
    private final HealthDataObserver mObserver = new HealthDataObserver(null) {

        // Update the sleep count when a change event is received
        public void onChange(String dataTypeName) {
            Log.d(MainActivity.TAG, "Observer receives a data changed event");

    public SleepCountReporter(HealthDataStore store) {
        mStore = store;

    public void start() {
        // Register an observer to listen changes of sleep count and get today sleep count
        HealthDataObserver.addObserver(mStore, HealthConstants.Sleep.HEALTH_DATA_TYPE, mObserver);

    // Read the today's sleep count on demand
    private void readTodaysleepCount() {
        HealthDataResolver resolver = new HealthDataResolver(mStore, null);

        // Set time range from start time of today to the current time
        long startTime = getStartTimeOfToday();
        long endTime = System.currentTimeMillis();
        HealthDataResolver.Filter filter = HealthDataResolver.Filter.and(HealthDataResolver.Filter.greaterThanEquals(HealthConstants.Sleep.START_TIME, startTime),
                HealthDataResolver.Filter.lessThanEquals(HealthConstants.Sleep.START_TIME, endTime));

        HealthDataResolver.ReadRequest request = new HealthDataResolver.ReadRequest.Builder()
                .setProperties(new String[]{HealthConstants.Sleep.HEALTH_DATA_TYPE})

        try {
        } catch (Exception e) {
            Log.e(MainActivity.TAG, e.getClass().getName() + " - " + e.getMessage());
            Log.e(MainActivity.TAG, "Getting sleep count fails.");

    private long getStartTimeOfToday() {
        Calendar today = Calendar.getInstance();

        today.set(Calendar.HOUR_OF_DAY, 0);
        today.set(Calendar.MINUTE, 0);
        today.set(Calendar.SECOND, 0);
        today.set(Calendar.MILLISECOND, 0);

        return today.getTimeInMillis();


 Can anyone please look at it and help me to resolve the issue ?



Post Reply
Board View
Newbie roger.ka**** , 320 Seed Jan 13, 2018 13:44 Post #1 0
Typically, from what i've read about what seems to be your problem, this issue only happens on Samsung phones with android 7.0. Now, assuming you're dealing with an Android problem, you can try to see if this replicates on Android 7.1.2 available in Samsung's Developers Remote Test lab here 
You may also want to see if this problem discussed on SO is pertinent to you
But you'd have to provide more context into your problem in order to get better feedback and help? Can you elaborate a bit?

Post Reply
Board View
Newbie hakanl**** , 320 Seed Nov 13, 2018 07:26 Post #2 0
do you only get this error in sleep mode ? Can you share some more information? agario
Post Reply