Android 脚本设计之SL4A_Examples(1)

 

Android barcode scanner in 6 lines of Python code

After my last video about using a barcode scanner to add and search books in your library, I was feeling pretty happy. Bar code scanners are pretty cheap–mine cost about $65. But thenGoogle released the Android Scripting Environment (ASE) and it turns out that you don’t even need a bar code scanner. Instead, you can use an Android phone such as the G1.

Just as a proof-of-concept, here’s a barcode scanner written in six lines of Python code:

import android
droid = android.Android()
code = droid.scanBarcode()
isbn = int(code['result']['SCAN_RESULT'])
url = “http://books.google.com?q=%d” % isbn
droid.startActivity(‘android.intent.action.VIEW’, url)

Thanks to fellow Googler Vijayakrishna Griddaluru for sending me this sample code.

import android

droid=android.Android()

name=droid.getInput("Hello!","What is your name?")

droid.makeToast("Hello, %s" %name.result)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值