User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

sample_code:get_device_specs

This is an old revision of the document!


Table of Contents

Get Device Specs

I have been asked more than once lately about the device on which I am testing code.

In order to produce some of the answers simply, I wrote a simple function getDeviceSpecs(). It occurred to me that this may be useful to others when reporting problems on the discussion groups.

Sample code

The sample app uses this function to display some specs and copy them to the clipboard, ready to pass elsewhere.

getDeviceSpecs.js
//Called when application is started.
function OnStart()
{
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );    
 
    //Create a button and add it to layout.
    btn = app.CreateButton( "Test" );
    btn.SetOnTouch(btn_OnTouch);
    lay.AddChild( btn );
    
    //Add layout to app.    
    app.AddLayout( lay );
}
 
function btn_OnTouch()
{
   var tst = getDeviceSpecs();
   app.Alert(tst);
   app.SetClipboardText(tst);
}
 
function getDeviceSpecs()
{
  var os =app.GetOSVersion();
  var model = app.GetModel();
  var tablet = app.IsTablet();
//Get screen dimensions. 
  var sw = app.GetScreenWidth(); 
  var sh = app.GetScreenHeight(); 
  var dens = app.GetScreenDensity();
//Get display dimensions. 
  var dw = app.GetDisplayWidth(); 
  var dh = app.GetDisplayHeight();
 
//specs are formatted as a comment so we can paste
//them somewhere convenient
  var s = "/*\nos=" + os+"\n"+
        "tablet="+ tablet + "\n"+
        "model=" + model + "\n" +
        "screen width="+ sw + "\n" + 
        "screen height="+ sh + "\n" + 
        "screen density="+ dens + "\n" + 
        "display width="+ dw + "\n" + 
        "display height="+ dh +"\n*/"; 
   return(s);
}

Notes

The function getDeviceSpecs at the end of the code, can be pasted independently into a project an the string returned can be used however you see fit.

sample_code/get_device_specs.1421527185.txt.gz · Last modified: 2015/01/18 04:39 (external edit)