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 : 4 View : 28285 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 7ryanwalker , 630 Seed Apr 21, 2017 08:22 Post #1 0
Earth Day Quotes
Happy Earth Day Quotes
Earth Day Wishes
Happy Earth Day Wishes
Earth Day Messages
Happy Earth Day Messages
Earth Day Images
Happy Earth Day Images
Earth Day Wallpaper
Happy Earth Day Wallpaper
Earth Day Pictures
Happy Earth Day Pictures
Post Reply
Board View
Newbie y5zone , 540 Seed Jul 20, 2017 12:08 Post #2 0
It was a great article on mbr membrane bioreactor. Thank you
Post Reply
Board View
Newbie y5zone , 540 Seed Jul 21, 2017 05:33 Post #3 0
DO check this out as we provide international supplies
mbr system
mbr process
membrane bioreactors
mbr membrane bioreactor
mbr sewage treatment plant
mbr technology in wastewater treatment
membrane bioreactor wastewater treatment
membrane bioreactors for wastewater treatment
uf filter
uf membrane filter
ultra filtration system
ultrafiltration system
ultrafiltration membranes
water filter bottle
gravity water purifier

Water-Code
http://www.water-code.com
Post Reply
Board View
Newbie gearboxrepairmalaysia , 210 Seed Nov 05, 2017 16:03 Post #4 0
gearbox repair specialist Malaysia
auto transmission repair
gearbox specialist
https://gearboxrepair.com.my
Post Reply