K
K
Kostya Bakay2016-02-01 15:59:29
Java
Kostya Bakay, 2016-02-01 15:59:29

How to execute certain code only for smartphones, ignoring tablets?

I just need to temporarily somehow restrict the work of a certain code for tablets, since it does not work on tablets as it should, and without it everything is fine, but I need to leave the code for phones. Here I would like to just select a block of code and tell it to work only on phones in the same place.
Something like this:

if (код выполняется на телефоне == true) {
// код для телефона
} else {
// код для планшета
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
razer89, 2016-02-01
@kostyabakay

In the values ​​folder, create a bool.xml file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="is_tablet">false</bool>
</resources>

In the values-sw600dp folder, create a bool.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="is_tablet">true</bool>
</resources>

In code:
isTablet will be set to true if the app is running on a tablet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question