All Python Sample Scripts
HelloWorld
# coding:utf-8
print "Hello, world!"
CopySample
import android
droid = android.Android()
text = ""
text = text + "import android\n"
text = text + "droid = android.Android()\n"
text = text + "droid.makeToast(\"using Python\")\n"
text = text + "droid.vibrate()\n"
text = text + "droid.notify(\"using Python\",\"Message\")\n"
text = text + "#line comment\n"
text = text + "\"\"\"\n"
text = text + "block comment\n"
text = text + "\"\"\"\n"
text = text + "print \"using Python\"\n"
droid.dialogGetInput("Sample","using Python",text)
result = droid.dialogGetResponse().result
if result.has_key('which') and result['which'] == 'positive':
droid.setClipboard(result['value'])
droid.makeToast(result['value'])
else:
droid.makeToast("Copy canceled")
DatePicker
import datetime
import android
droid = android.Android()
droid.makeToast("Input your birthday");
now = datetime.datetime.today();
year = now.year;
month = now.month;
day = now.day;
droid.dialogCreateDatePicker(year,month,day);
droid.dialogShow();
response = droid.dialogGetResponse().result;
droid.dialogDismiss();
age = year-response['year'];
if ( (month<response['month']) or
((month==response['month']) and (day<response['day'])) ) :
age=age-1;
droid.dialogCreateAlert("Dialog","Age:"+str(age));
droid.dialogSetPositiveButtonText("OK");
droid.dialogShow();
droid.dialogGetResponse();
droid.dialogDismiss();
Dialog
import android
droid = android.Android()
droid.dialogCreateAlert("Dialog","with Python")
droid.dialogSetPositiveButtonText("Yes")
droid.dialogSetNegativeButtonText("No")
droid.dialogSetNeutralButtonText("Cancel")
droid.dialogShow()
response = droid.dialogGetResponse()
result = response.result["which"]
droid.dialogDismiss()
droid.makeToast(result)
DualToneMultiFrequency
import android
#import sys
droid = android.Android()
numbers = ["3","2","1233","3","22","2","39","9","3","2","1233","3","22","3","2","1"]
durations = [384,128,256,512,256,512,256,512,384,128,256,512,256,384,128,1024]
def gTone(number,duration):
droid.generateDtmfTones(number,duration)
return
for i in range(0,len(numbers)) :
print numbers[i]
# sys.stdout.write(numbers[i])
gTone(numbers[i],durations[i])
GetInput
import android
droid = android.Android()
droid.dialogGetInput("dialogGetInput","using Python")
result = droid.dialogGetResponse().result
if result.has_key('which') and result['which'] == 'positive' :
droid.notify("dialogGetInput using Python",result['value'])
else :
droid.makeToast("dialogGetInput using Python:"+result['which'])
HorizontalProgress
import android
import time
droid = android.Android()
droid.dialogCreateHorizontalProgress("Horizontal","using Python");
droid.dialogShow()
value = 0
while value < 100 :
value = value + 1
droid.dialogSetCurrentProgress(value)
time.sleep(0.01)
droid.dialogDismiss()
LaunchBrowser
import android
droid = android.Android()
droid.launch("com.android.browser.BrowserActivity")
LaunchCalculator
import android
droid = android.Android()
droid.launch("com.android.calculator2.Calculator")
LaunchCalendar
import android
droid = android.Android()
droid.launch("com.android.calendar.LaunchActivity")
LaunchGallery
import android
droid = android.Android()
droid.launch("com.cooliris.media.Gallery")
LaunchMusic
import android
droid = android.Android()
droid.launch("com.android.music.MediaPlaybackActivityStarter")
LaunchSetting
import android
droid = android.Android()
droid.launch("com.android.settings.Settings")
LaunchSoundRecorder
import android
droid = android.Android()
droid.launch("com.android.soundrecorder.SoundRecorder")
MediaVolume
import android
droid = android.Android()
vol = droid.getMediaVolume().result
maxvol = droid.getMaxMediaVolume().result
droid.dialogCreateSeekBar(vol,maxvol,"Media volume","")
droid.dialogSetPositiveButtonText("OK")
droid.dialogSetNegativeButtonText("Cancel")
droid.dialogShow()
response = droid.dialogGetResponse()
droid.dialogDismiss()
if response.result["which"] == "positive" :
droid.setMediaVolume(response.result["progress"])
droid.makeToast("Volume:"+str(droid.getMediaVolume().result))
else :
droid.makeToast("Cancel pressed")
Notify
import android
droid = android.Android()
droid.notify("Notify using Python","Message")
OptionsMenu
# coding:utf-8
import android
droid = android.Android()
print "Press Menu Button"
droid.addOptionsMenuItem("From Python","menu",1,"ic_menu_info_details")
droid.addOptionsMenuItem("Exit Python","menu",2,"ic_menu_close_clear_cancel")
while True:
event = droid.eventWaitFor("menu")
if event.result["data"] == 1:
droid.makeToast("Selected Add Menu")
elif event.result["data"] == 2:
break
droid.clearOptionsMenu()
droid.makeToast(__file__+" is done")
PackageCui
import android
droid = android.Android()
pack= droid.getRunningPackages()
for i in pack.result :
print str(droid.getPackageVersion(i).id)+"."+i+"/ver"+str(droid.getPackageVersion(i).result)
PhoneCall
import android
droid = android.Android()
droid.phoneCallNumber("117")
QR
import android
droid = android.Android()
extras = {}
extras['ENCODE_TYPE'] = 'TEXT_TYPE'
extras['ENCODE_DATA'] = 'Python'
intent = droid.makeIntent('com.google.zxing.client.android.ENCODE', None, None, extras).result
droid.startActivityIntent(intent)
RecognizeSpeech
import android
droid = android.Android()
text= droid.recognizeSpeech()
droid.makeToast(text.result)
droid.notify("Recognize Speech using Python",text.result)
print(text.result.encode("utf-8"))
Scancode
import android
droid = android.Android()
droid.scanBarcode()
clip = droid.getClipboard()
text = clip.result
droid.makeToast(text)
Search
import android
droid = android.Android()
droid.search("Python")
SendEmail
import android
droid = android.Android()
droid.sendEmail("sl4@email.fake","sendEmail","using Python")
ShowFilename
import android
droid = android.Android()
droid.makeToast(__file__)
ShowThis
import android
droid = android.Android()
def load_text(name):
text = ""
fih = open(name)
while 1:
line = fih.readline()
if not line:
break
text = text+line
fih.close
return text
print load_text(__file__)
ShowWeb
import android
droid = android.Android()
droid.webViewShow('http://www.google.com')
Speak
import android
droid = android.Android()
droid.ttsSpeak("Speak using Python")
SpinnerProgress
import android
import time
droid = android.Android()
droid.dialogCreateSpinnerProgress("Spinner","using Python");
droid.dialogShow()
time.sleep(2)
droid.dialogDismiss()
StartRingtone
import android
droid = android.Android()
droid.startActivity("android.intent.action.RINGTONE_PICKER")
Toast
import android
droid = android.Android()
droid.makeToast("Toast using Python")
Vibrate
import android
droid = android.Android()
droid.makeToast("Vibrate using Python")
droid.vibrate()
return