My phone is a Nexus One Froyo but these scripts will run on most phones (time of writing this: 14 July 2010).
ASE is a way of running python scripts on an Android phone. Its very easy to set it up (http://code.google.com/p/android-scripting/ – just download the python apk – it installs like an ordinary App) and the libraries have twitter and json already there. You can edit on the phone itself.
My phone is a Nexus One Froyo but these scripts will run on most phones.
Script 1 (as simple as you can get!)
*****************
print “python test”
*****************
Script 2 (make Toast label thingy)
*****************
import android
droid = android.Android()
droid.makeToast(‘Hello, Android!’)
******************
Script 3 (alert dialogue)
*****************
import android
droid = android.Android()
droid.dialogCreateAlert(‘my title’, ‘my message bla bla’)
droid.dialogShow()
******************
Script 4 (post a twitter update, libraries already there)
******************
import android
import twitter
droid = android.Android()
twitter_name = droid.getInput(”,’Twitter name?’).result
twitter_password = droid.getInput(”,’Twitter password?’).result
twitter_update = droid.getInput(”,’Update message?’).result
t = twitter.Api(username=twitter_name, password=twitter_password)
update = t.PostUpdate(twitter_update)
print update.text
#print twitter_password
#print twitter_update
print ‘ \n\n done it ‘
*************************
Script 5 (posts to twitter your phone location)
***********************
import android
import twitter
droid = android.Android()
# Login to twitter account.
twitter_name = droid.getInput(”,’Twitter name?’).result
twitter_password = droid.getInput(”,’Twitter password?’).result
t = twitter.Api(username=twitter_name, password=twitter_password)
# get phones location data
location = droid.getLastKnownLocation().result
# print a bit of interesting data
print str(location.keys())
print ‘latitude is ‘ + str(location.values()[0]['latitude'])
print ‘longitude is ‘ + str(location.values()[0]['longitude'])
# update twitter
update = t.PostUpdate(‘My location is: http://maps.google.com/maps?q=’+str(location.values()%5B0%5D%5B'latitude'%5D)+’,'+str(location.values()[0]['longitude'])+”)
# if no errors this will print
print ‘\n\nDone it’
droid.makeToast(‘done it’)
**************************
Script 5 (speaks text)
*************************
import android
droid = android.Android()
say_it = droid.getInput(”,’Say what?’).result
if say_it:
droid.ttsSpeak(say_it)
else:
droid.ttsSpeak(‘You forgot to enter something in the previous text box.’)
********************************
Script 6 (sends an email, user must confirm)
********************************
import android
recipientAddress = ‘blabla@gmail.com’
subject = ‘test from android’
body = ‘testing…’
droid = android.Android()
droid.sendEmail(recipientAddress,subject,body)
*******************************
Script 7 (takes photo and puts in gallery folder)
*******************************
import android
droid = android.Android()
fileName = droid.getInput(”,’Photo name?’).result
if fileName:
droid.cameraCapturePicture(‘/sdcard/DCIM/Camera/’ + fileName + ‘.jpg’)
else:
fileName = ‘billpic’
droid.cameraCapturePicture(‘/sdcard/DCIM/Camera/’ + fileName + ‘.jpg’)
print ‘you called it billpic’
print ‘you called it: ‘ + fileName
***********************************


