Site Moved

This blog has been moved to blog.justain.net
and no longer updated. Please visit my new blog. All existing blog post is there.

Posted in Uncategorized | Leave a comment

How to deploy updated source code in emulator without restart

In case you have started the emulator to test a source code, and you have updated the code and would like to deploy to the emulator. You certainly don’t want to turn off the on the emulator (which is wasting the time).

You can try following method:

mmm packages/apps/Contacts
adb -s emulator-5554 remount
adb -s emulator-5554 sync

Posted in Android | Tagged | Leave a comment

Android Build System Q&A All in One

Outdated Build system documentation
http://source.android.com/porting/build_system.html

In general, the key thing to note is that android build system is non-recursive. For more on recursive vs non-recursive, please see GNU Make Recursion “http://www.gnu.org/s/hello/manual/make/Recursion.html

Why recursion is harmful
http://www.google.co.in/url?
sa=t&source=web&cd=1&ved=0CBkQFjAA&url=http%3A%2F

%2Faegis.sourceforge.net
%2Fauug97.pdf&ei=nWmITZonhLywA9KqjYIM&usg=AFQjCNHNpBwPrZj4wjVZcyFfqmagq0M2JQ&sig2=d0fecnqbexy71nytu4PguQ”

= FAQ =
All the commands mentioned here are from top of the tree and assume
you’ve already setup your environment with

$ source build/envsetup.sh
$ choosecombo

== What java version is my build using? ==

In Gingerbread, your JAVA_HOME is set to ”’/usr/lib/jvm/java-6-sun”’
by build/envsetup.sh. You may see errors if you do not have JAVA 1.6
installed.

$ echo $JAVA_HOME # should return empty
$ source build/envsetup.sh # will set your JAVA_HOME if it’s empty,
will honor the existing value otherwise
$ which java
$ java -version
$ javac -version

=== Related Build Error: method does not override a method from its
superclass. @Override ===

This “error” is due to a difference in the meaning of @Override
between Java 1.5 and Java 1.6: Java 1.6 added the ability to use
@Override to indicate that a method implements an interface method
[which this code does].

You should be able to compile this code without error if you use a
Java 1.6 compiler (the ‘java -version’ command only shows the JRE
version.  Use ‘javac -version’ to get the compiler version and adjust
your path accordingly).

== What are the various build variants and their usage ==

Android build system supports the following build variants

*user
*userdebug
*eng
*tests

For more on their usage and meaning, please see the Android Build
Variants wiki
http://source.android.com/porting/
build_system.html#androidBuildVariants

You can build these variants as follows

$ cd WORKSPACE
$ source build/envsetup.sh
$ choosecombo 1 1 <product-name> user
$ choosecombo 1 1 <product-name> userdebug
$ choosecombo 1 1 <product-name> eng

Alternatively, you can run

$ make PRODUCT-<product-name>-user
$ make PRODUCT-<product-name>-eng
$ make PRODUCT-<product-name>-tests

Note that ”’choosecombo”’ doesn’t support tests variant. More
details on
tests variant TBD.

== Where is the build log? ==
You can save one for yourself with

$ make 2>&1 | tee log

== How do I clean the build? ==

You can use ”’dataclean”’ to clean the staging area for your data
partition

$ make dataclean # will rm -rf $(PRODUCT_OUT)/data/*, data-qemu/*,
userdata-qemu.img

You can use ”’installclean”’ while switching between build variants

$ choosecombo 1 1 <product-name> user
$ make installclean # deletes all of the files that change between
different
build types
$ choosecombo 1 1 <product-name> eng

Clean and clobber, both will remove the entire build dir

$ make clean   # Remove all builds for current and past targets, does
rm -rf
$(OUT_DIR)
$ make clobber # Remove all builds for current and past targets

== What is a module? ==

In android build system, an Android.mk file defines how you build. An
android module is the entity you are building and is specified by
variable LOCAL_MODULE in the Android.mk

A single Android.mk can build multiple modules.

== How do I rebuild my module? ==

If you have a ‘LOCAL_MODULE := foobar’ in your Android.mk, you should
be able to do

$ make foobar

== How do I build multiple modules in a dir? ==
== What are m, mm, mmm? ==

These are build utilities provided by build/envsetup.sh. Here’s a
description of all the available utilities

– croot:   Changes directory to the top of the tree.
– m:       Makes from the top of the tree.
– mm:      Builds all of the modules in the current directory.
– mmm:     Builds all of the modules in the supplied directories.
– cgrep:   Greps on all local C/C++ files.
– jgrep:   Greps on all local Java files.
– mgrep:   Greps on all makefiles
– resgrep: Greps on all local res/*.xml files.
– godir:   Go to the directory containing a file
– printconfig: tells you what configuration you are currently
building

Note that ‘m’ and ‘mm’ need a toplevel Android.mk in the directory you
use them on.

Example usage

$ cd dalvik/tests
$ mm
$ mmm ../tools
$ godir Atomic.h
$ m
$ croot

== How do I turn off prelinking for my module? ==

Add

LOCAL_PRELINK_MODULE := false

For the module in your Android.mk LOCAL_PRELINK_MODULE is set to false
by default for executables (built using BUILD_EXECUTABLE)

== How do I see what commands make is running? ==

You can use the ”’showcommands”’ modifier target.
What is does (build/core/config.mk)
# The ‘showcommands’ goal says to show the full command
# lines being executed, instead of a short message about
# the kind of operation being done.
SHOW_COMMANDS:= $(filter showcommands,$(MAKECMDGOALS))

Usage
$ make showcommands
$ cd $some_dir_with_an_Android.mk
$ mm showcommands

== How do I find out what are the available modules? ==

$ cd $some_dir_with_an_Android.mk
$ mm modules

You can also run ‘make’ to see the list of all the modules available
in your tree
$ croot
$ make modules

== How do I clean a single module/package? ==

$ croot
$ make clean-$(LOCAL_MODULE)

== How do I rebuild system image for an existing build? ==

$ make snod

=== What is snod? ===

‘snod’ is a pseduo-target provided by build/core/Makefile. You can use
it to rebuild your system image without following it’s dependencies
and rebuilding everything else, apart from what you provide to make.
Example use cases

$ make framework snod # rebuilds framework module, and system image

== How do I build multiple variants and targets? ==

Note: this script is broken in gingerbread.

$ source build/tools/check_builds.sh
$ golden_builds <product1>-eng <product2>-user <product3>-eng

Additionally you can run

$ check_builds <product1>-eng <product2>-user <product2>-eng

What this will do for you, according to check_build.sh comments:

# Go get dinner, and when you get back, there will be a file
# test-builds/sizes.html that has a pretty chart of which files are
# in which tree, and how big they are.

== How do I find what build properties are available for my build and
how they were derived? ==
Post a full build, build properties can be examined in

out/target/product/$(TARGET_PRODUCT)/build.prop

This file is created/updated by build/core/Makefile (invoked by build/
core/main.mk). The file is a concatentation of build/tools/
buildinfo.sh output + your system.prop + $ADDITIONAL_BUILD_PROPERTIES

== App development ==

$ cd your_app_folder
$ mmm
$ adb sync

If you don’t use the same machine for compilation and loading it is
possible to forward the port used by adb (5037) to the PC connected to
the device.
If it’s a linux machine, it is a lot easier, but it is possible to
forward ports from windows.
Fastboot still has to be run on the connected machine, but since it
only needs a few image files it is easier to coordinate.

== How do I build my binary/library/applicaton? ==

In general, refer to the build cookbook “http://source.android.com/
porting/build_cookbook.html
” You can also look at existing Android.mk
files in your source tree. If you are tagging your module with
“optional”.

In summary, ‘user’ tags cannot be used, they are used only for legacy
modules (Grandfathered).

‘optional’ tags makes sure that the module gets installed into user
and eng builds as long as you add that module name to the list of
packages (PRODUCT_PACKAGES).

PRODUCT_PACKAGES for proprietary modules is defined in the device-
vendor.mk
file, e.g. vendor/<vendor-name>/prop/common/config/device-vendor.mk

Opensource modules are defined in device/<vendor-name>/common/
common.mk

The ‘eng’ tag implies that the module will be picked up only by ‘eng’
variant of the
build.

The tests tag implies that the module will be picked up by tests
variant of the
build. The tests variant is not available from choosecombo.

Do not use development (or any other tags not sanctioned by the
android build
system)

== My binary/library isn’t available on target, whats wrong? ==

Check if you’ve updated the appropriate .mk configuration file to
include
a PRODUCT_PACKAGES entry for the module.

Check the build log to see if your module got built. You can also use
‘mm’
with ‘showcommands’ to see if the module is being built & installed.

== I don’t want to build everything, takes too long. What do I do? ==

You can build “tiny android,” an Android build with a limited
userspace that
is useful for kernel development and verification. The tiny android
build will
not boot into the full UI. It will stay at one of the loading screens
(ANDROID_ – not the boot animation). ADB will be active, allowing you
to run
unit tests, etc. The build time for tiny android is significantly less
than a
full Android build. Tiny Android builds complete in less than 2
minutes,
whereas a full Android build takes over 20 minutes.

$ BUILD_TINY_ANDROID=true make -j4

=== How do I use a prebuilt kernel? ===

The kernel objects, vmlinux and zImage will be at <platform>/out/
target/product/<TARGET>/obj/KERNEL_OBJ and its subdirectories, where
<TARGET> is the target device you selected in choosecombo above.  You
can override the TARGET_PREBUILT_KERNEL flag with your own kernel
image to build android with your kernel, as follows:

$ make -j4 TARGET_PREBUILT_KERNEL=”<your_kernel_tree>/arch/arm/boot/
zImage”

=== error: do_inode_allocate_extents: Failed to allocate blocks ===
One way to workaround this is to increase the system image size.
Please see
BOARD_*_PARTITION_SIZE variables in device/<vendor>/$(TARGET_PRODUCT)/
BoardConfig.mk in your workspace.

== Misc ==

=== If you want to see all warnings in a pretty format, do ===
$ build/tool/warn.py my_build_log > warn.html

See the html page for a nice classification for all the warnings on
your product.

=== What is the ‘simulator’ in lunch for? ===

“the simulator is somewhat maintained, but it’s a very specialized
and
very fragile tool which is only used by a handful of people at
Google.
It is likely to require the very precise environment that those
people”
use, which is specific to Google and isn’t publicly available.”

See this thread for more detail
http://groups.google.com/group/android-building/browse_thread/thread/
55521a7849bbac1a/e4e020a8213cf7c7?lnk=gst&q=generic
+product#e4e020a8213cf7c7

=== How do I rebuild the sdk? ===

$ make PRODUCT-sdk-sdk

== What is the difference between board, target, product and device?
==

Android build system supports hierarchical layering of product,
device, board,
and arch in a one to many relationship as described at
http://source.android.com/porting/
build_system.html#androidBuildSystemLayers

=== TARGET ===
In Android Build System, ‘target’ or ‘TARGET’ refers to your build
target. There are a bunch of variables associated with a target.

From a Build perspective, these are

TARGET_PRODUCT: identifies the product that you are building
TARGET_BUILD_TYPE: identifies the build type from one of ‘release,
debug’
TARGET_BUILD_VARIANT: identifies the build variant from one of ‘user,
userdebug, eng, tests’

From a PRODUCT perspective, these are

TARGET_PRODUCT: identifies the product, for example, full_crespo,
passion_us, passion_eu
TARGET_DEVICE: identifies the device, for example, full_crespo,
passion
TARGET_BOARD_PLATFORM: can be used for a family of boards, for
example, qsd8k, msm7k
TARGET_BOOTLOADER_BOARD_NAME: used by OEMs for their boards, and by
chipset_variants. For example, mahimahi of htc, full_crespo
TARGET_ARCH: arm/x86
TARGET_ARCH_VARIANT: armv5/armv7

=== BOARD ===

In Android Build System, BOARD refers to the schematics of a product
http://source.android.com/porting/
build_system.html#androidBuildSystemLayers

=== DEVICE ===

For OEMs, DEVICE refers to the physical layer of plastic on the device
http://source.android.com/porting/
build_system.html#androidBuildSystemLayers

Each of these devices may result
into multiple products. Examples
* crespo  # Samsung
* passion # HTC

=== PRODUCT ===
The product layer represents a complete specification of a shipping
product
http://source.android.com/porting/
build_system.html#androidBuildSystemLayers

== How do I add a new target? ==
Adding a new target means adding a new product. You can name your
product as chipset_variant. Note that if one product may suffice for
all your chipset variants.

== How do I add a new product? ==
Follow the instructions for configuring a new product “http://
source.android.com/porting/build_new_device.html” for general info.

Android products use inheritance, you can generate a nice product
graph using

$ sudo apt-get install graphviz
$ make product-graph # pdf goes in out/product.pdf

== PRODUCT CONFIGURATION ==
In general, android build system builds products, and allows you to
configure what goes into a product. It doesn’t explicitly support
configuration at a build level, in allowing you to choose what to
build. A typical android build is supposed to build all possible code
that is available
http://android.git.kernel.org/?p=platform/build.git;a=blob;f=core/
main.mk;h=3877bb2b784da528fc20d66dc2701bdb0e3703b5;hb=HEAD”
see build/core/main.mk line 638-639.

You can choose what goes into a product, by adding to the
PRODUCT_PACKAGES list which is used to specify what additional
packages go into a product, as follows.

=== How do I generate a product graph ===
$ sudo apt-get install graphviz
$ make product-graph # pdf goes in out/product.pdf

=== What is device-vendor.mk, when do I modify it? ===

device-vendor.mk allows you to configure proprietary modules to be
installed
on the target images.

Starting with Gingerbread the Android build system enforces an
explicit
LOCAL_MODULES_TAGS for all modules which aren’t in the GRANDFATHERED
MODULES
list in “http://android.git.kernel.org/?p=platform/
build.git;a=blob;f=core/
user_tags.mk;h=3eade8aa840e5c2fe0c31babf7b437d3fdf37feb;hb=HEAD” and
recommends using “optional” tag for modules which are expected to be
in all builds of a product.

When LOCAL_MODULE_TAGS of a module is defined with an “optional” tag,
the module will not be available in the generated final image/s (which
will be flashed on Target).

To get the module available in final image/s, module has to be part of
PRODUCT_PACKAGES list.

=== What is device/<vendor>/common/common.mk, when do I modify it? ===

The opensource counter part of device-vendor.mk [prev question] is
device/<vendor>/common/common.mk and should be used for adding
opensource modules to PRODUCT_PACKAGES.

=== How do I configure (enable/disable) a module? ===
Configuration has two aspects with respect to Android Build System
* What gets installed
* What gets built

What gets installed can be configured at a product level using the
device-vendor.mk and common.mk configuration files, described above
[prev questions].

Controlling what get’s built, is a more complicated story. Presently,
for a typical build android build system builds all modules it can
find using findleaves.py [See modules_to_install and modules_to_check
in build/core/main.mk]. The two ways to enable/disable a module then
are

* Add/Remove Android.mk
* Wrap the Android.mk in TARGET_PRODUCT if you don’t want to build
your
* modules for products like generic, emulator etc.

If you want your module to not be built for variants not supported by
your LOCAL_MODULE_TAGS, you can define LOCAL_DONT_CHECK_MODULE, though
it is not recommended by android build system as of now. Example,

$(CLEAR_VARS)
LOCAL_DONT_CHECK_MODULE := true
LOCAL_MODULE := foo
LOCAL_MODULE_TAGS := eng

What this will do for you is
* For all non-eng builds, your module will only be built if it’s a
dependency
* of another module
* Else, it will be ignored

== Emulator ==
=== What is the emulator? ===
From the AOSP WIKI documentation: “The Android SDK includes a mobile
device emulator — a virtual mobile device that runs on your computer.
The emulator lets you develop and test Android applications without
using a physical device.”

http://developer.android.com/guide/developing/devices/emulator.html
Emulator Overview”

=== How is it used? ===
The emulator is provided by

external/qemu
sdk/emulator
prebuilt/linux-x86/emulator

The one in external/qemu produces an executable called “emulator”
which can be used from the commandline. It get’s built and installed
in out/host/linux-x86/bin/emulator and can be used with the images
generated by building the ‘generic’ products provided in the AOSP
tree. The AOSP tree provides “non-hardware-specific targets” which can
be used “to build entire user-level system and work with emulator”.

There are two such target products available

target/product/generic
target/product/generic_x86

They use the following boards from target/board, respectively

target/board/generic
target/board/generic_x86

(There’s also an ’emulator’ board available under target/board for
which
there’s no emulator.mk under target/product, device/ or vendor/ which
is where
envsetup.sh looks for product makefiles, and so it doesn’t show up in
choosecombo)

target/board/*/README.txt explains the existence and usage of all
three,
generic, generic_x86, emulator.

More documentation about the sdk emulator and it’s usage at
http://developer.android.com/guide/developing/tools/emulator.html
developer guide for emulator”

Emulator usage example
http://groups.google.com/group/android-platform/browse_thread/thread/
b115c4cadbfdb333/488ca1b48bc546d8?lnk=gst&q=generic
+product#488ca1b48bc546d8

== How do I rebuild the emulator? ==

http://groups.google.com/group/android-building/browse_thread/thread/
f8f0c3bacd6efae/05ec2449d4e5dc6f?lnk=gst&q=emulator#05ec2449d4e5dc6f

Posted in Android | Tagged | Leave a comment

To customize Android source code

There are 2 ways to customize the Android source code.

  1. Build a customized image for emulator to run
  2. Customize part of the apk package during emulator runtime

Way 1

  1. Move your customized apk package to sourceDirectory/out/target/product/generic/system/app
  2. Delete apk package you don’t want it in same directory
  3. Run “make snod” in source directory
  4. Run “emulator” in source directory, here we go for the customized android!!
  5. For safer approach, run “emulator -wipe-data” to erase all previously installed file
Way 2
  1. If your add additional packages,

    In Terminal 1
    adb shell
    #su
    #mount -o remount -r -w -t yaffs2 /dev/block/mtdblock3 /system

    In Terminal 2, go to the .apk containing folder

    adb push myApp.apk /system/app/

  2. If you alter existing packages,
    1. Run “mmm packages/apps/<package altered without .apk>” at source directory
    2. If you can’t execute mmm, try to run “. build/envsetup.sh” first
    3. Run step 1 to push the package to running emulator

Note that way 2 is not persistent and if you run emulator with wipe data, you will remove the pushed apk. In this case, you need to do way 1.

Posted in Android | Tagged | Leave a comment

Android: using R.styleable

R.styleable is used for getting out value from a typed array. To facilitate:

1. Create a file “attrs.xml” under directory “res/values”, write as

<resources>
<declare-styleable name=”Favorite”>
<attr name=”className” format=”string” />
<attr name=”packageName” format=”string” />
<attr name=”spanX” format=”string” />
<attr name=”spanY” format=”string” />
<attr name=”x” format=”string” />
<attr name=”y” format=”string” />
</declare-styleable>
</resources>

2. Define your own xml element using the attributes name under directory “res/xml”

<favorites xmlns:launcher=”http://schemas.android.com/apk/res/com.rtx.launcher”&gt;

<appwidget
launcher:packageName=”com.android.music”
launcher:className=”com.android.music.MediaAppWidgetProvider”
launcher:screen=”2″
launcher:x=”0″
launcher:y=”1″
launcher:spanX=”4″
launcher:spanY=”1″
/>

</favorites>

3. Put xml attributes’ definition to set collection’s value (at java class)

TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.Favorite);

4. Then you can get the value (at java class)

int spanX = a.getInt(R.styleable.Favorite_spanX, 0);

Example of using R.styleable

private void parserXml() throws XmlPullParserException, Throwable {
XmlResourceParser parser = getResources()
.getXml(R.xml.default_favorite);
AttributeSet set = Xml.asAttributeSet(parser);
depth = parser.getDepth();
System.out.println(depth);
int type;
while (((type = parser.next()) != XmlPullParser.END_TAG || parser
.getDepth() > depth)
&& type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
continue;
}
TypedArray a = this.obtainStyledAttributes(set,
R.styleable.Favorite);
String name = parser.getName();
if (name.equals(“favorite”)) {
String packageName = a
.getString(R.styleable.Favorite_packageName);
String className = a.getString(R.styleable.Favorite_className);
String screen = a.getString(R.styleable.Favorite_screen);
String x = a.getString(R.styleable.Favorite_x);
String y = a.getString(R.styleable.Favorite_y);
System.out.println(packageName + “/t” + className + “/t”
+ screen + “/t” + x + “/t” + y);
}
   a.recycle();//
}
}
Posted in Android | Tagged | 1 Comment

Merge several git commits into one using REBASE

Warning: This is only for the local commits without pushing to the remote repos. And any commits that is shared with others are NOT RECOMMEND to do the merging.

So let’s say you’ve just made 4 commits, and you want to make one larger commit out of them.

$ git rebase -i HEAD~4

pick 01d1124 Adding license
pick 6340aaa Moving license into its own file
pick ebfd367 Jekyll has become self-aware.
pick 30e0ccb Changed the tagline in the binary, too.

# Rebase 60709da..30e0ccb onto 60709da
#
# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

So, a few things have happened here. First of all, I told Git that I wanted to rebase using the last four commits from where the HEAD is with HEAD~4. Git has now put me into an editor with the above text in it, and a little explanation of what can be done. You have plenty of options available to you from this screen, but right now we’re just going to squash everything into one commit. So, changing the first four lines of the file to this will do the trick:

pick 01d1124 Adding license
squash 6340aaa Moving license into its own file
squash ebfd367 Jekyll has become self-aware.
squash 30e0ccb Changed the tagline in the binary, too.

Basically this tells Git to combine all four commits into the the first commit in the list. Once this is done and saved, another editor pops up with the following:

# This is a combination of 4 commits.
# The first commit's message is:
Adding license

# This is the 2nd commit message:

Moving license into its own file

# This is the 3rd commit message:

Jekyll has become self-aware.

# This is the 4th commit message:

Changed the tagline in the binary, too.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i nor -o; assuming --only paths...
# Not currently on any branch.
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#	new file:   LICENSE
#	modified:   README.textile
#	modified:   Rakefile
#	modified:   bin/jekyll
#

Since we’re combining so many commits, Git allows you to modify the new commit’s message based on the rest of the commits involved in the process. Edit the message as you see fit, then save and quit. Once that’s done, your commits have been successfully squashed!

Created commit 0fc4eea: Creating license file, and making jekyll self-aware.
 4 files changed, 27 insertions(+), 30 deletions(-)
  create mode 100644 LICENSE
	Successfully rebased and updated refs/heads/master.

So, this has been a relatively painless so far. If you run into conflicts during the rebase, they’re usually quite easy to resolve and Git leads you through as much as possible. The basics of this is fix the conflict in question, git add the file, and then git rebase –continue will resume the process. Of course, doing a git rebase –abort will bring you back to your previous state if you want. If for some reason you’ve lost a commit in the rebase, you can use the reflog to get it back.
There’s plenty of other uses for git rebase -i that haven’t been covered yet. If you have one you’d like to share, please do so! GitCasts also has a fantastic video on this process as a whole that also covers some more complex examples of the command.

P.S.
In case you accidentally quit the process during rebase, just type to quit:

#git rebase -i --abort
Posted in Uncategorized | Tagged | Leave a comment

How to push .apk to Android /system/app/

To push Launcher.apk to /system/app/

In Terminal 1
adb shell
#su
#mount -o remount -r -w -t yaffs2 /dev/block/mtdblock3 /system

In Terminal 2, go to the .apk containing folder
adb push myApp.apk /system/app/

Posted in Android | Tagged , , | Leave a comment

AppWidget於Launcher內的啟動原理

AppWidget的啟動原理

在開機過程中,java層進程System Server啟動後(這個進程管理著所有的系統service, 例如
activity manager service, windows manager service, power manager service等),會創建
AppWidgetService的實例,並調用它的SystemReady()方法,在這個方法裡,它做了三件事:

  1. 遍歷所有的安裝包,找到符合條件ACTION=ACTION_APPWIDGET_UPDATE和<meta-data android:name=”android.appwidget.provider”/>的intent receiver,解析相關信息,保存到本地數據成員中。
  2. 讀取本地文件數據:/data/system/appwidgets.xml,所有已安裝到桌面的widget的信息都保存在這個文件裡。讀出來,也保存到本地數據成員裡。
  3. 註冊了三個消息:ACTION_BOOT_COMPLETED(系統啟動到桌面就會發送此消息),ACTION_PACKAGE_ADDED(有新APK包安裝到系統),ACTION_PACKAGE_REMOVED(有APK包被刪除)。當系統啟動到桌面後,AppWidgetService接收到了ACTION_BOOT_COMPLETED消息,它會去檢查本地數據成員,如果有已經安裝到桌面的widget,它會上發ACTION_APPWIDGET_ENABLED和ACTION_APPWIDGET_UPDATE消息。如果有widget設置了updatePeriodMillis的屬性,它就會開始計時(這個是通過AlarmManager來實現的),到時間時,就會再次上發ACTION_APPWIDGET_UPDATE消息。
Posted in Uncategorized | Tagged | Leave a comment

Impossible to create default appwidget in custom build Android launcher

Normally, in order to create some default widgets on desktop, you must need to use bindAppWidgetId(), the workflow would be like this:

  1. widget host create a widgetId.
  2. bindAppWidgetId() to that widgetId
  3. Add the host view to desktop using createView()

Then when you debug the Launcher project, the logcat output securityException…, it
said the pid user don’t have the BIND_WIDGET permission.

The fact is that BIND_WIDGET permission is just for WidgetPicker Activity
(DialogActivity), it’s not for use bindAppWidgetId() function. Based on the reply of Android Team, it’s for security reason of not to expose the permission to add widget apart from UI selection.

Google said, “This is deliberately not available to applications.  If you want to add a widget, you need to launch the selector UI for the user to pick the widget which will then take care of the bind.  Widgets can expose a lot of private data of all types, so it is not safe to allow an application to arbitrarily bind to them without the user implicitly approving (through the selection UI).”

So it is IMPOSSIBLE to create default widget if the launcher is just application, or unless you are not the manufacturer of the phone (ridiculous though).

Posted in Android | Tagged | Leave a comment

How to read data of Android Emulator SQLite Database in Eclipse

There is a software which can be embedded into Eclipse which called Questoid SQLite Browser

Here are the steps of the configuration:

  1. Download the Questoid Plugin
  2. Place the file in your Eclipse plugins folder (e.g. /usr/lib/eclipse/plugins)
  3. Restart Eclipse
  4. Start up an Android Emulator w/ Debugging in Eclipse
  5. Switch to the DDMS Perspective in Eclipse
  6. Go to the ‘File Explorer’ tab to locate your device’s database file
  7. Navigate to: e.g. ‘data -> data -> com.myproject -> databases -> myproject
  8. Open the database file in Questoid (see screen shot)
  9. Switch to the ‘Questoid SQLite Browser’ tab that appears (mine appears next to LogCat by default)
  10. Switch to the ‘Browse Data’ sub tab
  11. Select your table from the drop down menu
  12. Browse your data here
Posted in Android | Tagged , | 3 Comments