2011/07/24

python tips: python scripting on android and remotecontrol

* Overview
SL4A(Script Layer for Android) enables you to execute several script language (such as python, ruby, ...) on your android devices. Today I tried to SL4A and remotecontrol which enables you to remotely execute python code from your non-android computer (such as linux, windows...).

- SL4A installation steps are introduced here
- RemoteControl setup steps are described here
- SL4A API is also described here

* Get location and geocode from android device (RemoteControl)
yaboo@maniac:~/Downloads/android-sdk-linux_x86/platform-tools$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import android
>>> droid = android.Android(('192.168.10.4', 46522)) # public server mode
>>> droid.startLocating()
Result(id=0, result=None, error=None)
>>> loc = droid.readLocation().result
>>> loc
{u'network': {u'altitude': 0, u'provider': u'network', u'longitude': 139.***69349999998, u'time': 1311439075865, u'latitude': 35.***094566666668, u'speed': 0, u'accuracy': 75}, u'gps': {u'altitude': 58.9000244140625, u'provider': u'gps', u'longitude': 139.***20321081579, u'time': 1311439081000, u'latitude': 35.***270288087428, u'speed': 0, u'accuracy': 55}}
>>> n = loc['network']
>>> la = n['latitude']
>>> lo = n['longitude']
>>> la
35.***094566666668
>>> lo
139.***69349999998
>>> address = droid.geocode(la, lo).result
>>> print repr(address).decode('unicode-escape')
[{u'thoroughfare': u'*丁目', u'locality': u'**市', u'admin_area': u'**県', u'feature_name': u'27', u'country_code': u'JP', u'country_name': u'日本'}]
>>> droid.stopLocating()
Result(id=3, result=None, error=None)


* Testing TelephonyManager functionality
>>> print droid.getDeviceId().result
3568***********
>>> print droid.getCellLocation().result
{u'lac': 145, u'cid': 99008715}
>>> print droid.getDeviceSoftwareVersion().result
01
>>> print droid.getNeighboringCellInfo().result
[]
>>> print droid.getNetworkOperator().result
44010
>>> print droid.getNetworkOperatorName().result
NTT DOCOMO
>>> print droid.getPhoneType().result
gsm
>>> print droid.getSimCountryIso().result
jp
>>> print droid.getSimOperator().result
44010
>>> print droid.getSimOperatorName().result

>>> print droid.getSimSerialNumber().result
89811**************
>>> print droid.getSimState().result
ready
>>> print droid.SubscriberId().result
com.googlecode.android_scripting.rpc.RpcError: Unknown RPC.
None

* Testing Batterymanager API
>>> droid.batteryStartMonitoring()
Result(id=24, result=None, error=None)
>>> print droid.batteryCheckPresent().result
True
>>> print droid.batteryGetHealth().result
2
>>> print droid.batteryGetLevel().result
74
>>> print droid.batteryGetPlugType().result
2
>>> print droid.batteryGetPlugType().result
1
>>> print droid.batteryGetStatus().result
2
>>> print droid.batteryGetTechnology().result
Li-ion
>>> print droid.batteryGetTemperature().result
360
>>> print droid.batteryGetVoltage().result
4057
>>> print droid.readBatteryData().result
{u'status': 2, u'temperature': 380, u'level': 74, u'battery_present': True, u'plugged': 1, u'health': 2, u'voltage': 4057, u'technology': u'Li-ion'}
>>> droid.batteryStopMonitoring()
Result(id=35, result=None, error=None)

* Testing CommonIntentsFacade
>>> droid.viewMap(u"*****") # android device open google map!!!
Result(id=40, result=None, error=None)

* Testing ContactsFacade
>>> droid.contactsGetCount().result
301

* Testing WifiFacade
>>> print droid.wifiGetConnectionInfo().result
{u'ssid': u'**********', u'bssid': u'00:0d:02:f7:**:**', u'network_id': 0, u'supplicant_state': u'completed', u'link_speed': 54, u'mac_address': u'04:**:65:**:**:18', u'rssi': -57, u'ip_address': 67***24, u'hidden_ssid': False}
>>> print droid.wifiGetScanResults().result
[{u'capabilities': u'[WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP]', u'frequency': 2467, u'ssid': u'logitec51', u'bssid': u'00:01:8e:f2:**:c0', u'level': -82}, {u'capabilities': u'[WEP]', u'frequency': 2442, u'ssid': u'**********', u'bssid': u'00:0d:02:f7:c0:bc', u'level': -55}]

No comments:

Post a Comment

100