'Programmatically/Automatically disable GPS when not used
When Android apps ask for the GPS to be enabled, after the app is turned off, GPS is not automatically turned off. I suspect this is not only the case on my Honor 10, but on most Android phones. This is a privacy and a energy wasting concern.
Is there a way to disable GPS after the app has been closed? I only find old, outdated answers to that question, or that it's not possible.
Both apps that do this, as well as sample code would be fine with me.
Solution 1:[1]
OK, I reply myself, it was quite easy in fact :
const getFilterValues = (state, resource) => {
let values = undefined;
if (!state || !resource) return values;
let filterJSON =
state.router &&
state.router.location &&
state.router.location.query &&
state.router.location.query.filter;
if (filterJSON) {
let filters = JSON.parse(decodeURIComponent(filterJSON));
if (filters) {
values = filters;
}
}
else {
filterJSON =
state.admin &&
state.admin.resources &&
state.admin.resources[resource] &&
state.admin.resources[resource].list &&
state.admin.resources[resource].list.params &&
state.admin.resources[resource].list.params.filter;
if (filterJSON) {
values = filterJSON;
}
}
return values;
};
const mapStateToProps = (state, props) => {
let filters = getFilterValues(state, 'tags');
return {
...props,
filters
};
};
const CustomTagList = connect(
mapStateToProps,
)(TagList);
Don't forget to change last lines of code :
export default compose(
connect(undefined, { push }),
withStyles(styles)
)(CustomTagList);```
Now you have props.filters value in TagEdit. :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joël |
