![Yoctopuce Yocto-GPS Скачать руководство пользователя страница 113](http://html1.mh-extra.com/html/yoctopuce/yocto-gps/yocto-gps_user-manual_3415557113.webp)
it stays connected. To enable the Yoctopuce library to correctly manage these authorizations, your
must provide a pointer on the application context by calling the EnableUSBHost method of the YAPI
class before the first USB access. This function takes as arguments an object of the
android.content.Context
class (or of a subclass). As the Activity class is a subclass of
Context
, it is simpler to call
YAPI.EnableUSBHost(this);
in the method
onCreate
of your
application. If the object passed as parameter is not of the correct type, a
YAPI_Exception
exception is generated.
...
@Override
public
void
onCreate
(
Bundle savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
)
;
try
{
// Pass the application Context to the Yoctopuce Library
YAPI.
EnableUSBHost
(this)
;
}
catch
(
YAPI_Exception e
)
{
Log.
e
(
"Yocto"
,e.
getLocalizedMessage
())
;
}
}
...
Autorun
It is possible to register your application as a default application for a USB module. In this case, as
soon as a module is connected to the system, the application is automatically launched. You must
add
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
in the
section
<intent-filter>
of the main activity. The section
<activity>
must have a pointer to an XML file
containing the list of USB modules which can run the application.
<manifest xmlns:android=
"http://schemas.android.com/apk/res/android"
...
<uses-feature android:name=
"android.hardware.usb.host"
/>
...
<application ... >
<activity
android:name=
".MainActivity"
>
<intent-filter>
<action android:name=
"android.intent.action.MAIN"
/>
<action android:name=
"android.hardware.usb.action.USB_DEVICE_ATTACHED"
/>
<category android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
<meta-data
android:name=
"android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource=
"@xml/device_filter"
/>
</activity>
</application>
</manifest>
The XML file containing the list of modules allowed to run the application must be saved in the res/
xml directory. This file contains a list of USB
vendorId
and
deviceID
in decimal. The following
example runs the application as soon as a Yocto-Relay or a YoctoPowerRelay is connected. You can
find the vendorID and the deviceID of Yoctopuce modules in the characteristics section of the
documentation.
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<resources>
<usb-device vendor-id=
"9440"
product-id=
"12"
/>
<usb-device vendor-id=
"9440"
product-id=
"13"
/>
</resources>
16. Using the Yocto-GPS with Android
www.yoctopuce.com
107
Содержание Yocto-GPS
Страница 1: ...Yocto GPS User s guide...
Страница 2: ......
Страница 6: ...22 Characteristics 557 Blueprint 559 Index 561...
Страница 10: ...4 www yoctopuce com...
Страница 14: ...8 www yoctopuce com...
Страница 18: ...12 www yoctopuce com...
Страница 22: ...16 www yoctopuce com...
Страница 38: ...32 www yoctopuce com...
Страница 42: ...36 www yoctopuce com...
Страница 54: ...48 www yoctopuce com...
Страница 72: ...66 www yoctopuce com...
Страница 92: ...86 www yoctopuce com...
Страница 122: ...116 www yoctopuce com...
Страница 132: ...126 www yoctopuce com...
Страница 159: ...20 High level API Reference On failure throws an exception or returns a negative error code www yoctopuce com 153...
Страница 564: ...22 Characteristics 558 www yoctopuce com...
Страница 565: ......
Страница 566: ......