Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - lamer

#1
Hi menion,
to me it seems that this problem is not python specific. But rather a design flaw in the AndroidFacadeAPI. All the script  calls are encoded using JSON, which is meant to handle unicode data. Therefore there is no way in python to create 'invalid' utf8 to transport raw 8-bit data. To only solution I can imagine is reimplement the the whole AndroidFaceAPI call  in order to bypass the default python JSON encoding for the locus specific data structure.
#2
Yes it is. There is the Scripting Layer for Android (SL4A) http://code.google.com/p/android-scripting/
It might be not suitable for real apps, meant to be handed out to someone.
#3
Developers / showing points from Python
April 14, 2011, 10:59:08
I tried to supply points from python using your data structure. Unfortunaly i get Errors because the SL4A backend tries to parse the 'extra data' as JSON or to encode it to JSON.
import android
import sqlite3
import struct

def geostd(droid,lat,lon):
url='geo:%s,%s'% (lat,lon)
droid.startActivity('android.intent.action.VIEW',url)

def javautf(str1):
str2=str1.encode('utf8')
return struct.pack('>h',len(str2))+str2

def points2locus(points):
'''Takes a list of tuples
Name,HTML-desc,extradata,latitude,longitude,image
'''
return struct.pack('>i',len(points))+
''.join([struct.pack('>i',len(point[5]))+point[5]+
''.join([javautf(str3) for str3 in point[0:3]])+
struct.pack('>dd',point[3],point[4]) for point in points])

def geolocus(droid,points):
extras={'extraDataName':points2locus(points)}
droid.startActivity('android.intent.action.VIEW','menion.points:extraDataName', None,None, extras, False)

droid = android.Android()
sqlc = sqlite3.connect('/sdcard/wiglewifi/wiglewifi.sqlite')
cur=sqlc.cursor()
cur.execute('select * from network where ssid=? limit 10',('eduroam',))
result= cur.fetchall()
sqlc.close()

#geostd(droid,result[0][5],result[0][6])
geolocus([(row[1],row[0],'',row[5],row[6],'') for row in result])

 request = json.dumps(data)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 43: unexpected code byte

has anyone an idea how to create und submit such datastructure in python?