Subscription preference

Notification emails are sent to your Samsung account email address.

* Email : anonymous@samsung.com

  

Close

Android Sleep Time

Forums View
Started by Newbie anshul.t , 140 Seed Apr 18, 2017 07:58 Replies : 2 View : 204340 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 (com.samsung.health.sleep) 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:


Code

 
public class SleepCountReporter {

    private final HealthDataStore mStore;
    private final HealthResultHolder.ResultListener<HealthDataResolver.ReadResult> mListener = new HealthResultHolder.ResultListener<HealthDataResolver.ReadResult>() {
        @Override
        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) {
                    c.close();
                }
            }
            MainActivity.getInstance().drawSleepCount(String.valueOf(count));
        }
    };
    private final HealthDataObserver mObserver = new HealthDataObserver(null) {

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

    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);
        readTodaysleepCount();
    }

    // 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()
                .setDataType(HealthConstants.Sleep.HEALTH_DATA_TYPE)
                .setProperties(new String[]{HealthConstants.Sleep.HEALTH_DATA_TYPE})
                .setFilter(filter)
                .build();

        try {
            resolver.read(request).setResultListener(mListener);
        } 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 ?

Tags

AndroidSDK

Post Reply
Board View
Newbie roger.kamena , 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 http://developer.samsung.com/remotetestlab/rtlDeviceList.action# 
You may also want to see if this problem discussed on SO is pertinent to you https://stackoverflow.com/questions/30703845/exception-on-serialization-on-samsung-galaxy-s5
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 mandysingh7388 , 210 Seed May 14, 2018 00:48 Post #2 0
Hey, I think the issue has already been solved by the user - Roger.kamena.
Really appreciable. 
Have a look to Blackmart apk with which the same happens.

Thanks,
Mandy
Post Reply