Use Python to develop Android applications: Section 2: the first practical application

Source: Internet
Author: User
Document directory
  • Step 1: Call the barcode scanner, scan the book's barcode, and then obtain the ISBN number of the book from the barcode.
  • Step 2: Construct a Url for querying book prices and use the book search function of Douban.
  • Part 3: Open the browser, input the constructed Url address, and return the search result
This section

1. python knowledge in this section
2. Function Analysis of the book price Calculator
3. Design and Implementation of the book price Calculator

1. python prerequisites

# Is Used for single-line comments. # subsequent content is comments and will not be interpreted and executed by the interpreter;
The import Statement is used to import the module, followed by the module name;
You do not need to declare the type of the variable in python. The type is automatically specified after the variable is assigned a value, which is also a feature of Dynamic Language;

Tuples, one of the basic python data structures, are expressed in this form: tuples 1 = (data 1, data 2, data 3)
Once the tuples are generated, they cannot be modified.
Tuples can be nested into a set of all list types including their own, such as: tuples 2 = (tuples 1, data 4, data 5)
How to obtain data in tuples: [index number]

Dictionary, one of the basic python data structures, expressed in this form: dictionary 1 = {key 1: value 1, key 2: Value 2, key 3: Value 3}
A dictionary can be nested with a set of all list types, including its own.
How to obtain data in a dictionary: dictionary name [key name] or dictionary name [index number]

Formatted string: % s in the string will be replaced by the following objects, for example:
'Hello, % s' % 'pulil'
The returned result is:
Hello, PuLee
Note that the % number between two strings should not be missed!

2. the first step is to call the bar code scanner, scan the bar code of the book, and then obtain the ISBN number of the book from the bar code. The second step is to construct a Url for querying the book price, using Douban's book search function Part 3: Open the browser, input the constructed Url address, and return the search result 3. design and Implementation of the book price Calculator

The implementation code is as follows:
# Import the Android API module
Import android
# Obtain the operation object
Droid = android. Android ()
# Run the scanner and return a tuples
Code = droid. scanBarcode ()
# Obtain the isbn number from the tuples returned by the scanner
Isbn = code [1] ['extras'] ['Scan _ result']
# Construct a Url for querying books
Url = 'HTTP: // book.douban.com/subject_search? Search_text = % s & cat = 1001 '% isbn
# Open the browser, input the constructed Url, and return the search result
Droid. startActivity ('android. intent. action. view', url)

The final returned query result is as follows:

This article references the article: http://www.mattcutts.com/blog/android-barcode-scanner/

Welcome to join the Douban SL4A group to discuss progress: Douban SL4A group (http://www.douban.com/group/SL4A)

The article is reproduced from:Iron ride (http://cooleep.com /)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.