This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
sample_code:get_device_specs [2015/12/18 21:50] administrator remove confusing comment |
sample_code:get_device_specs [2017/11/25 19:46] (current) stevegarman [Sample code] |
||
---|---|---|---|
Line 8: | Line 8: | ||
<code JavaScript getDeviceSpecs.js> | <code JavaScript getDeviceSpecs.js> | ||
- | var allBuilds = JSON.parse('{'+ | + | var allBuilds = JSON.parse('{' + |
- | '"1":{"level":1,"codename":"(no code name)","version":"1.0"}, ' + | + | '"1":{"level":1,"codename":"(no code name)","version":"1.0"}, ' + |
- | '"2":{"level":2,"codename":"(no code name)","version":"1.1"} , ' + | + | '"2":{"level":2,"codename":"(no code name)","version":"1.1"} , ' + |
- | '"3":{"level":3,"codename":"Cupcake","version":"1.5"}, ' + | + | '"3":{"level":3,"codename":"Cupcake","version":"1.5"}, ' + |
- | '"4":{"level":4,"codename":"Donut","version":"1.6"}, ' + | + | '"4":{"level":4,"codename":"Donut","version":"1.6"}, ' + |
- | '"5":{"level":5,"codename":"Eclair","version":"2.0"}, ' + | + | '"5":{"level":5,"codename":"Eclair","version":"2.0"}, ' + |
- | '"6":{"level":6,"codename":"Eclair","version":"2.0.1"}, ' + | + | '"6":{"level":6,"codename":"Eclair","version":"2.0.1"}, ' + |
- | '"7":{"level":7,"codename":"Eclair","version":"2.1"}, ' + | + | '"7":{"level":7,"codename":"Eclair","version":"2.1"}, ' + |
- | ' "8":{"level":8,"codename":"Froyo","version":"2.2.x"}, ' + | + | ' "8":{"level":8,"codename":"Froyo","version":"2.2.x"}, ' + |
- | ' "9":{"level":9,"codename":"Gingerbread","version":"2.3 - 2.3.2"}, ' + | + | ' "9":{"level":9,"codename":"Gingerbread","version":"2.3 - 2.3.2"}, ' + |
- | ' "10":{"level":10,"codename":"Gingerbread","version":"2.3.3 - 2.3.7"}, ' + | + | ' "10":{"level":10,"codename":"Gingerbread","version":"2.3.3 - 2.3.7"}, ' + |
- | ' "11":{"level":11,"codename":"Honeycomb","version":"3.0"}, ' + | + | ' "11":{"level":11,"codename":"Honeycomb","version":"3.0"}, ' + |
- | ' "12":{"level":12,"codename":"Honeycomb","version":"3.1"}, ' + | + | ' "12":{"level":12,"codename":"Honeycomb","version":"3.1"}, ' + |
- | ' "13":{"level":13,"codename":"Honeycomb","version":"3.2.x"}, ' + | + | ' "13":{"level":13,"codename":"Honeycomb","version":"3.2.x"}, ' + |
- | ' "14":{"level":14,"codename":"Ice Cream Sandwich","version":"4.0.1 - 4.0.2"}, ' + | + | ' "14":{"level":14,"codename":"Ice Cream Sandwich","version":"4.0.1 - 4.0.2"}, ' + |
- | ' "15":{"level":15,"codename":"Ice Cream Sandwich","version":"4.0.3 - 4.0.4"}, ' + | + | ' "15":{"level":15,"codename":"Ice Cream Sandwich","version":"4.0.3 - 4.0.4"}, ' + |
- | ' "16":{"level":16,"codename":"Jelly Bean","version":"4.1.x"}, ' + | + | ' "16":{"level":16,"codename":"Jelly Bean","version":"4.1.x"}, ' + |
- | ' "17":{"level":17,"codename":"Jelly Bean","version":"4.2.x"}, ' + | + | ' "17":{"level":17,"codename":"Jelly Bean","version":"4.2.x"}, ' + |
- | ' "18":{"level":18,"codename":"Jelly Bean","version":"4.3.x"}, ' + | + | ' "18":{"level":18,"codename":"Jelly Bean","version":"4.3.x"}, ' + |
- | ' "19":{"level":19,"codename":"KitKat","version":"4.4 - 4.4.4"}, ' + | + | ' "19":{"level":19,"codename":"KitKat","version":"4.4 - 4.4.4"}, ' + |
- | ' "20":{"level":20,"codename":"K or L","version":"4 or 5"}, ' + | + | ' "20":{"level":20,"codename":"K or L","version":"4 or 5"}, ' + |
- | ' "21":{"level":21,"codename":"Lollipop","version":"5.0"}, ' + | + | ' "21":{"level":21,"codename":"Lollipop","version":"5.0"}, ' + |
- | ' "22":{"level":22,"codename":"Lollipop","version":"5.1"}, ' + | + | ' "22":{"level":22,"codename":"Lollipop","version":"5.1"}, ' + |
- | ' "23":{"level":23,"codename":"Marshmallow","version":"6.0"} ' + | + | ' "23":{"level":23,"codename":"MarshMallow","version":"6.0"}, ' + |
- | ' }' ); | + | ' "24":{"level":24,"codename":"Nougat","version":"7.0"}, ' + |
+ | ' "25":{"level":25,"codename":"Nougat","version":"7.1"}, ' + | ||
+ | ' "26":{"level":26,"codename":"Oreo","version":"8.0.0"} ' + | ||
+ | ' }'); | ||
- | var osObj = allBuilds[app.GetOSVersion()] | + | var osObj = allBuilds[app.GetOSVersion()] |
try | try | ||
{ | { | ||
- | var osInfo = "Android "+ osObj.version +" (" + | + | var osInfo = "Android " + osObj.version + " (" + |
- | osObj.codename + ") API level " + | + | osObj.codename + ") API level " + |
- | osObj.level | + | osObj.level |
} | } | ||
catch(err) | catch(err) | ||
{ | { | ||
- | var osInfo = app.GetOSVersion(); | + | var osInfo = app.GetOSVersion(); |
} | } | ||
- | + | var txt; | |
- | //Called when application is started. | + | //Called when application is started. |
- | function OnStart() | + | function OnStart() |
{ | { | ||
+ | //Lock orientation | ||
+ | app.SetOrientation( app.GetOrientation() ); | ||
+ | //Create a layout with objects vertically centered. | ||
+ | var lay = app.CreateLayout("linear", "VCenter,FillXY"); | ||
+ | lay.SetBackColor("#ffddffff"); | ||
- | //Create a layout with objects vertically centered. | + | // create viewr for specs |
- | var lay = app.CreateLayout( "linear", "VCenter,FillXY" ); | + | scroll = app.CreateScroller(1, 0.9); |
+ | var specs = getDeviceSpecs(); | ||
+ | txt = app.CreateText(specs, 1, 0.9, "left,multiLine"); | ||
+ | txt.SetPadding(0.1); | ||
+ | txt.SetTextColor("#ff446666"); | ||
+ | scroll.AddChild(txt); | ||
+ | lay.AddChild(scroll); | ||
- | //Create a button and add it to layout. | + | //Create a button and add it to layout. |
- | var btn = app.CreateButton( "Test" ); | + | var btn = app.CreateButton("[fa-copy]", -1, -1, "fontAwesome,custom"); |
- | btn.SetOnTouch(btn_OnTouch); | + | btn.SetTextColor("#ffddffff"); |
- | lay.AddChild( btn ); | + | btn.SetStyle("#4285F4", "#2265d4", 2, "#999999", 0, 1, "#ff9000"); |
- | + | ||
- | //Add layout to app. | + | btn.SetOnTouch(btn_OnTouch); |
- | app.AddLayout( lay ); | + | lay.AddChild(btn); |
+ | |||
+ | //Add layout to app. | ||
+ | app.AddLayout(lay); | ||
} | } | ||
- | function btn_OnTouch() | + | function btn_OnTouch() |
{ | { | ||
- | var tst = getDeviceSpecs(); | + | app.SetClipboardText(txt.GetText( ) ); |
- | app.Alert(tst); | + | // flash |
- | app.SetClipboardText(tst); | + | txt.SetBackColor( "#44000000" ); |
+ | setTimeout( function(){ | ||
+ | txt.SetBackColor( "#00000000" );} | ||
+ | ,100); | ||
} | } | ||
- | function getDeviceSpecs() | + | function getDeviceSpecs() |
{ | { | ||
- | var os =app.GetOSVersion(); | + | var os = app.GetOSVersion(); |
- | var model = app.GetModel(); | + | var model = app.GetModel(); |
- | var tablet = app.IsTablet(); | + | var tablet = app.IsTablet(); |
- | var fromapk = ( app.GetAppPath() == "/Assets" ) | + | var fromapk = (app.GetAppPath() == "/Assets") |
- | var dsversion = app.GetDSVersion(); | + | var dsversion = app.GetDSVersion() |
- | //Get screen dimensions. | + | //Get screen dimensions. |
- | var sw = app.GetScreenWidth(); | + | var sw = app.GetScreenWidth(); |
- | var sh = app.GetScreenHeight(); | + | var sh = app.GetScreenHeight(); |
- | var dens = app.GetScreenDensity(); | + | var dens = app.GetScreenDensity(); |
- | //Get display dimensions. | + | //Get display dimensions. |
- | var dw = app.GetDisplayWidth(); | + | var dw = app.GetDisplayWidth(); |
- | var dh = app.GetDisplayHeight(); | + | var dh = app.GetDisplayHeight(); |
- | //Get drive details | + | //Get drive details |
- | var intfld = app.GetInternalFolder(); | + | var intfld = app.GetInternalFolder(); |
- | var extfld = app.GetExternalFolder(); | + | var extfld = app.GetExternalFolder(); |
- | var intspace = app.GetFreeSpace("internal"); | + | var intspace = app.GetFreeSpace("internal"); |
- | var extspace = app.GetFreeSpace("external"); | + | var extspace = app.GetFreeSpace("external"); |
- | + | var mem = app.GetMemoryInfo().total.toLocaleString("en-US"); | |
- | //specs are formatted as a comment so we can paste | + | |
- | //them somewhere convenient | + | //specs are formatted as a comment so we can paste |
- | try {os=osInfo;} | + | //them somewhere convenient |
- | catch(err){} | + | try |
- | var s = "/*\n"+ | + | { |
- | "os=" + os+"\n"+ | + | os = osInfo; |
- | "tablet="+ tablet + "\n"+ | + | } |
- | "model=" + model + "\n" + | + | catch(err) |
- | "DroidScript=" + dsversion + "\n"+ | + | {} |
- | "screen width="+ sw + "\n" + | + | var s = "/*\n" + |
- | "screen height="+ sh + "\n" + | + | "os=" + os + "\n" + |
- | "screen density="+ dens + "\n" + | + | "tablet=" + tablet + "\n" + |
- | "display width="+ dw + "\n" + | + | "model=" + model + "\n" + |
- | "display height="+ dh +"\n" + | + | "DroidScript=" + dsversion + "\n" + |
- | "internal folder=" + intfld + "\n" + | + | "screen width=" + sw + "\n" + |
- | "external folder=" + extfld + "\n" + | + | "screen height=" + sh + "\n" + |
- | "int free space=" + intspace + "\n" + | + | "screen density=" + dens + "\n" + |
- | "ext free space=" + extspace + "\n" + | + | "display width=" + dw + "\n" + |
- | "country code="+app.GetCountryCode() +"\n"+ | + | "display height=" + dh + "\n" + |
- | "country="+app.GetCountry()+"\n"+ | + | "internal folder=" + intfld + "\n" + |
- | "language code="+app.GetLanguageCode() +"\n"+ | + | "external folder=" + extfld + "\n" + |
- | "language="+app.GetLanguage()+"\n"+ | + | "int free space=" + intspace + "\n" + |
- | "*/"; | + | "ext free space=" + extspace + "\n" + |
- | return(s); | + | "memory=" + mem +"\n" + |
+ | "country code=" + app.GetCountryCode() + "\n" + | ||
+ | "country=" + app.GetCountry() + "\n" + | ||
+ | "language code=" + app.GetLanguageCode() + "\n" + | ||
+ | "language=" + app.GetLanguage() + "\n" + | ||
+ | "wifi=" + app.GetIPAddress() + "\n" + | ||
+ | "*/"; | ||
+ | return(s); | ||
} | } | ||
</code> | </code> | ||
===== Notes ===== | ===== 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. | 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. |