![Yoctopuce Yocto-GPS User Manual Download Page 115](http://html1.mh-extra.com/html/yoctopuce/yocto-gps/yocto-gps_user-manual_3415557115.webp)
A real example
Launch you Java environment and open the corresponding sample project provided in the directory
Examples//Doc-Examples
of the Yoctopuce library.
In this example, you can recognize the functions explained above, but this time used with all the side
materials needed to make it work nicely as a small demo.
package
com.yoctopuce.doc_examples
;
import
android.app.Activity
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.AdapterView.OnItemSelectedListener
;
import
android.widget.ArrayAdapter
;
import
android.widget.Spinner
;
import
android.widget.TextView
;
import
com.yoctopuce.YoctoAPI.YAPI
;
import
com.yoctopuce.YoctoAPI.YAPI_Exception
;
import
com.yoctopuce.YoctoAPI.YAltitude
;
import
com.yoctopuce.YoctoAPI.YGps
;
import
com.yoctopuce.YoctoAPI.YModule
;
import
com.yoctopuce.YoctoAPI.YPressure
;
import
com.yoctopuce.YoctoAPI.YTemperature
;
public
class
GettingStarted_Yocto_GPS
extends
Activity
implements
OnItemSelectedListener
{
private
ArrayAdapter<String> aa;
private
String
serial =
""
;
private
Handler handler =
null
;
@Override
public
void
onCreate
(
Bundle savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
)
;
setContentView
(
R.
layout
.
gettingstarted_yocto_gps
)
;
Spinner my_spin =
(
Spinner
)
findViewById
(
R.
id
.
spinner1
)
;
my_spin.
setOnItemSelectedListener
(this)
;
aa =
new
ArrayAdapter<String>
(this
, android.
R
.
layout
.
simple_spinner_item
)
;
aa.
setDropDownViewResource
(
android.
R
.
layout
.
simple_spinner_dropdown_item
)
;
my_spin.
setAdapter
(
aa
)
;
handler =
new
Handler
()
;
}
@Override
protected
void
onStart
()
{
super
.
onStart
()
;
try
{
aa.
clear
()
;
YAPI.
EnableUSBHost
(this)
;
YAPI.
RegisterHub
(
"usb"
)
;
YModule module = YModule.
FirstModule
()
;
while
(
module !=
null
)
{
if
(
module.
get_productName
()
.
equals
(
"Yocto-GPS"
))
{
String
serial = module.
get_serialNumber
()
;
aa.
add
(
serial
)
;
}
module = module.
nextModule
()
;
}
}
catch
(
YAPI_Exception e
)
{
e.
printStackTrace
()
;
}
aa.
notifyDataSetChanged
()
;
handler.
postDelayed
(
r,
500
)
;
}
@Override
protected
void
onStop
()
{
super
.
onStop
()
;
handler.
removeCallbacks
(
r
)
;
YAPI.
FreeAPI
()
;
}
@Override
16. Using the Yocto-GPS with Android
www.yoctopuce.com
109
Summary of Contents for Yocto-GPS
Page 1: ...Yocto GPS User s guide...
Page 2: ......
Page 6: ...22 Characteristics 557 Blueprint 559 Index 561...
Page 10: ...4 www yoctopuce com...
Page 14: ...8 www yoctopuce com...
Page 18: ...12 www yoctopuce com...
Page 22: ...16 www yoctopuce com...
Page 38: ...32 www yoctopuce com...
Page 42: ...36 www yoctopuce com...
Page 54: ...48 www yoctopuce com...
Page 72: ...66 www yoctopuce com...
Page 92: ...86 www yoctopuce com...
Page 122: ...116 www yoctopuce com...
Page 132: ...126 www yoctopuce com...
Page 564: ...22 Characteristics 558 www yoctopuce com...
Page 565: ......
Page 566: ......