顯示具有 Android 標籤的文章。 顯示所有文章
顯示具有 Android 標籤的文章。 顯示所有文章

2011年2月9日 星期三

am related command note

1. start Activity
$am start -n <package-name>/.<class-name> // e.g., idv.funkie.pkg/.MyClass

2010年12月21日 星期二

Install sun jdk on ubuntu 10.10


Android requires JDK5.0 to build the source code (at the time of writing).
(When build Android, the java and javac version is checked by */build/core/main.mk)
So, you need to: download and install the JDK5.0 from Sun's (Oracle's) website, or, use the old repositories:

1a. For Java 5, Add Jaunty to repositories
$ sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ jaunty multiverse"

1b. For Java 6, Add Jaunty to repositories
$ sudo add-apt-repository ppa:sun-java-community-team/sun-java6
2. Update source list  
$ sudo apt-get update
3. Install 
$ sudo apt-get install sun-java6-jdk (or sun-java5-jdk)

2009年8月13日 星期四

Parsing XML on Android

基本上,要parsing XML 中的資料,有 SAX (Simple API for XML) 及 DOM (Document Object Model) 這兩種 APIs 可用。

SAX 優點:
 在於其記憶體使用量,一般遠低於 DOM 的使用量。因為 DOM 必須把整個 XML 樹放在記憶體,他的記憶體使用量和 XML 的大小成正比。而 SAX 所要耗費的的記憶體,卻是和 XML樹的最大深度相關。

SAX 缺點:
 雖然 SAX 有省記憶體的好處,不過當你的 XML 文件不是很大時,用 SAX 的方式,總是覺得要寫一堆的程式碼,而資料的處理也比較麻煩。

在Android上,目前確定支援SAX (DOM目前我還不確定是否支援) 。

SAX使用範例:
mSAXParserFactory = SAXParserFactory.newInstance();
mSAXParser = mSAXParserFactory.newSAXParser();
mParseHandler = new TreeParserHandler();startElement與endElement則是分別遇到起始的tag與結束的tag會被call,pAttributes物件即代表XML tag的attribute(e.g., <innertag sampleattribute="innertagAttribute" >),可使用atts.getValue("sampleattribute")來取得該屬性的值
mXMLReader = mSAXParser.getXMLReader();

// mParseHandler 為一繼承 org.xml.sax.helpers.DefaultHandler的// class的instance
mXMLReader.setContentHandler(mParseHandler);
mXMLReader.parse(
 new InputSource(參數為inputstream物件)
);
繼承 org.xml.sax.helpers.DefaultHandler
@Override
public void startDocument() throws SAXException {}

@Override
public void endDocument() throws SAXException {}

@Override
public void startElement(String pUri, String pLocalName,  String pName, Attributes pAttributes)
throws SAXException {}

@Override
public void endElement(String pUri, String pLocalName, String pQName) throws SAXException {}

@Override
public void characters(char[] pCh, int pStart, int pLength)
throws SAXException {}
主要是需Override以上幾個function,startDocument和endDocumet顧名思義就是parsing前與parsing後會call的callback。

startElement與endElement則是分別遇到起始的tag與結束的tag會被call,pAttributes物件即代表XML tag的attribute(e.g., <innertag sampleattribute="innertagAttribute" >),可使用atts.getValue(sampleattribute)來取得該屬性的值。

Note. 當在有使用xmlReader.setFeature時,startElement()與endElement()的參數pQName為XML tag名稱;反之,pLocalName為XML tag名稱。

以下為兩個參數的官方說明:
 pLocalName - the local name (without prefix), or the empty string if Namespace processing is not being performed.

 pQName - the qualified name (with prefix), or the empty string if qualified names are not available.

2009年7月16日 星期四

Activity.onCreateDialog()

官網原文:
Callback for creating dialogs that are managed (saved and restored) for you by the activity. If you use showDialog(int), the activity will call through to this method the first time, and hang onto it thereafter. Any dialog that is created by this method will automatically be saved and restored for you, including whether it is showing. If you would like the activity to manage the saving and restoring dialogs for you, you should override this method and handle any ids that are passed to showDialog(int). If you would like an opportunity to prepare your dialog before it is shown, override onPrepareDialog(int, Dialog).
換言之,當某一dialog已經過onCreateDialog() create過後,下一次在call Activity.showDialog(), 就會直接進Activity.onCreateDialog()而不會再進onCreateDialog()了。

2009年7月4日 星期六

How amazing - Activity.setContentView()

The Android Activity UI can be designed through write a xml file.I thought that's a very smart way and very different from tradition Java GUI programming (i.e., swing and awt) because that's very similar with what a web page designer dose, especially the table layout of Android.

When you define some UI component (e.g. a button) in a res/layout/xxx.xml, you maybe need to get the UI component instance to do something, such as register a click listener. Hence, Android supply Activity.findViewById(id of control) to get the component instance from the xml.

Note. you need call Activity.setContentView(xxx.xml) before invoking Activity.findViewById(componet id). By the way, the parameter(e.g., component id) must be defined in xxx.xml that is the parameter of setContentView(). Or you will get a null return value of findViewById().

2009年6月18日 星期四

bad class file. class file has wrong version 50.0, should be 4x.0.

When compiling your code using the JAR files, you may receive an error similar to the one below:
packages/apps/DMClient/src/com/asus/dm/DMMMIFactory.java:3: cannot access com.redbend.vdm.MmiChoiceList

bad class file: out/target/common/obj/JAVA_LIBRARIES/XXXX_intermediates/javalib.jar(com/XXXX/vdm/MmiChoiceList.class)

class file has wrong version 50.0, should be 49.0

Please remove or make sure it appears in the correct subdirectory of the classpath.

import com.XXXX.vdm.MmiChoiceList;
^

1 error

These types of errors are caused by a Java version mismatch between the compiled proxies and your runtime.

Below are a list of some of the version numbers and their corresponding Java runtimes:


Version 50.0 = Java 1.6.x
Version 49.0 = Java 1.5.x
Version 48.0 = Java 1.4.x


To resolve this issue, compile them with the right version of Java SDK

Android make command

targets - make targets will print a list of all of the LOCAL_MODULE names you can make.

clean-$(LOCAL_MODULE) and clean-$(LOCAL_PACKAGE_NAME) - Let you selectively clean one target. For example, you can type make clean-libutils and it will delete libutils.so and all of the intermediate files, or you can type make clean-Home and it will clean just the Home app.

modules - list the all modules that you can make.

Android.mk - app(apk) use c/++ and java library

When you want write an android app that built with Android source, you need create an Android.mk to indicate compiler how to do that.

If the app need use c/c++ & java library, the content of Android.mk is listed as below.



dir structure :

app
  |- AndroidManifest.xml
  |- Android.mk
  |- res
  |- src
  |- libs
       |- XXX.jar
       |- YYY.so
       |- Android.mk


The first Android.mk content :
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

############################################################
LOCAL_STATIC_JAVA_LIBRARIES := my-jar-lib
LOCAL_MODULE_TAGS := eng user
############################################################

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := DMClient

include $(BUILD_PACKAGE)

############################################################
include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
my-jar-lib:libs/XXX.jar

include $(BUILD_MULTI_PREBUILT)

include $(call all-makefiles-under,$(LOCAL_PATH))

LOCAL_STATIC_JAVA_LIBRARIES defines the java library.

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES
associates the lib name and jar file (represented by relative path) which is contributed by third party.

The last line means that includes all Android.mk which locate under the current path. In that way, the second Android.mk listed as below is included.



The second Android.mk content :

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_PREBUILT_LIBS := YYY.so

include $(BUILD_MULTI_PREBUILT)
The first line is important that announce YYY.so located in the current directory . If you didn't declare LOCAL_PATH (the first line), compiler will go to app/ to find XXX.so instead go to app/libs/ to find due to the second Android.mk is included by the first Android.mk.

2009年6月12日 星期五

Android docs path in device source tree

list some documents in android device source tree :

1. Android Build System :
- dev-src-root/build/core/build-system.html

2009年4月7日 星期二

Build android development toolkit (kit) for eclipse

The content described as below is reference android-source-root/development/tools/eclipse/README_WINDOWS.txt

1- To build the Eclipse plugin:
Under Linux:
$ cd your-device-directory
$ tools/eclipse/scripts/build_server.sh destination-directory

Note. destination-directory need a absolute path

This will create an "android-eclipse.zip" in the selected destination directory.

Then in Eclipse, you can use Help > Software Updates > Available Software > Archive > select the new android-eclipse.zip. Then with the new archive checked, click Install.

if you see the result shown as below that means build failed.
### development/tools/eclipse/scripts/create_all_symlinks.sh done
ECLIPSE_HOME not set, using /buildbot/eclipse-android as default
mkdir: cannot create directory `/buildbot': Permission denied
Please create a directory /buildbot/eclipse-android where Eclipse will be installed, i.e. execute 'mkdir -p /buildbot/eclipse-android && chown funkie /buildbot/eclipse-android'.


Please issue the command shown as below according to the prompt above to fix the problem.
$ sudo mkdir -p /buildbot/eclipse-android && sudo chown funkie /buildbot/eclipse-android

Note. In that way, the tools/eclipse/scripts/build_server.sh will download another eclipse into /buildbot/eclipse-android except you have set the ECLIPSE_HOME.


$ export ECLIPSE_HOME = <eclipse-dir>


Please window > preferences > select the sdk (path: android-device-source/out/host/linux-x86/sdk/android-sdk_eng.funkie_linux-x86) to set the android-sdk after finish build ADT.

2009年3月10日 星期二

Choose the target of the adb related command when you have more than one device or emultor....

1. look up the connectd device

$ adb devices

and you can see the result like described as below and the each line represents a serial number of each device or emulator

List of devices attached
HT837GZ03715 device
emulator-5554 device
emulator-5556 device

2. the symantic usage is

$ adb -s <> - directs command to the USB device or
emulator with
the given serial number


for example :

$ adb -s emulator-5554 shell


$ adb -s HT837GZ03715 shell

To build and use the adb under the Linux Environment

Black have try to use the ADB under Linux with only the USB connection. If you want to try, please following this quick guide:

1. build adb

$ make adb

2. putting the 50-android.rules into /etc/udev/rules.d/ (i.e., the path on linux host) and the content of

50-android.rules is listed as below

SUBSYSTEM=="usb", SYSFS{idVendor}=="05c6", MODE="0666"

the "05c6" can looked up through issuing the command as below when you have connected the device to linux host with USB.

$ lsusb

3. checking adb can detect the connected devices

$ kill `pgrep adb`

$adb devices

4. (optional step) if you want to connect to G1 you must open the "debug mode" by check the checkbox on Settings -> Application -> Development -> USB debuging