Skip to main content

Featured

Android studio “SDK tools directory is missing”

Following 2 possible solutions will resolve this problem :  Solution1 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:" Delete your  ~/.Android*  folders (losing all of your settings :/). Run Android Studio. It will show you a welcome wizard where it tries to download the SDK again (and fails due to my rubbish internet). Click the X on the wizard window. That will enable you to get to the normal welcome dialog. Go to Settings->Project Defaults->Project Structure and change the Android SDK location to the correct one. Solution 2 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:&quo

Code to identify device is small(phone/handset) or large(Tablet) in Android


Here the difference between a tablet and a phone is the screen size which is why you want to use different layout files. These files are stored in the res/layout-<qualifiers> directories. You can create an XML file in the directoy res/values-<same qualifiers> for each of your layouts and put an int/bool/string resource into it to distinguish between the layouts you use.

Example:

File res/values/screen.xml (assuming res/layout/ contains your layout files for handsets)
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="screen_type">phone</string>
</resources>

File res/values-sw600dp/screen.xml (assuming res/layout-sw600dp/ contains your layout files for small tablets like the Nexus 7)
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="screen_type">7-inch-tablet</string>
</resources>

File res/values-sw720dp/screen.xml (assuming res/layout-sw720dp/ contains your layout files for large tablets like the Nexus 10):
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="screen_type">10-inch-tablet</string>
</resources>
Now the screen type is accessible using the R.string.screen_type constant.

---------------------------------------------------------------------------------------------------------------------------
Another easiest way of detecting device type is to put different values in strings.xml for a single key, let's call it "device_type". So in:
  1. values -> strings.xml I will have <string name="device_type">smartphone</string>
  2. values-large -> strings.xml I will have <string name="device_type">tablet</string>
  3. values-small -> strings.xml I will have <string name="device_type">small</string>
  4. values-xlarge -> strings.xml I will have <string name="device_type">xlarge</string>
Having a context, I will read this value and determine what type of device I have.

Please refer the folllowing URl's for more information:
http://developer.android.com/guide/practices/screens_support.html 
http://developer.android.com/training/multiscreen/screensizes.html#TaskUseSWQuali 

Comments