2 How do I set background image to my application?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:background="@drawable/icon">
</RelativeLayout>
It's important to use RelativeLayout instead of LinearLayout.
Or use the following to set background programmatically:
layout = new AbsoluteLayout(this);
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.abc_bg_img);
BitmapDrawable background = new BitmapDrawable(bitmap);
layout.setBackgroundDrawable(background);
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.img_name);
imageView.setAdjustViewBounds(true);
imageView.setLayoutParams(new AbsoluteLayout.LayoutParams(100, 100, 100, 100));
layout.addView(imageView);
this.setContentView(layout);
3 How do I upgrade my project from SDK 1.0 to 1.5?
Download 1.5 SDK binary, and unzip it to a directory of your choice
Eclipse -> Preferences -> Android, replace your 1.0 location with 1.5 location
Open your project properties, select android tab, choose 1.5, then recompile your project
4 How do I change location of a View item?
Use setLeftAndRight() and setTopAndBottom(), remember to use view.invalidate() to trigger redraw.
5 How do I use Android Dev Phone with ATT?
Follow the steps given in the instructions that come with your phone. When the phone tries to connect to google to grab your dev account, click menu, then add a new APN with the following information:
Name: AT&T or anything you like
APN: isp.cingular
User: ISP@CINGULARGPRS.COM
Pass: CINGULAR1
Leave everything else untouched, you are done. Once you are able to connect, follow the instructions to setup everything else. A complete list of APNs from major carriers can be found here http://www.quickim.com/support/gprs-settings.html .
Other APNs you could try, username/pass are case sensitive
Cingular Orange
APN: WAP.CINGULAR
WAP@CINGULAR.COM --or-- WAP@CINGULARGPRS.COM
Password: CINGULAR1
Name: Cingular Blue
APN: proxy
No user or pass<
Name: Cingular Blue
APN: public
No user or pass
ATT IMS
Name: ims.cingular
Note that you may only be able to use EDGE instead of 3G on att network. This is because G1 wifi hardware only support 1700 tmobile network, while ATT uses 1900. Nothing can be done from software or configuration side.
6 How do I sync my gmail account with my Mac contacts?
Use A to G to convert your Mac contact to google csv
Import the newly generated csv to your google account, make sure you create a new google contact group, so you can remove everyone in that group if you don't want to leave the numbers in your gmail account.
In your G1, contacts, press menu, sync, done
7 How Do I remove an email account?
Press menu and go to "Accounts", then press and hold that account, a menu will pop up.
8 Upgrade your firmware
http://www.htc.com/www/support/android/adp.html
Note that in step 6 of upgrading radio firmware, when restarting phone to recovery mode, you must hold home key first, and then press power key.
In step 9 of upgrading the radio firmware, phone doesn't restart until you release home-back (triggered by key-up)
After you are done with everything, reboot process may take longer then usual, so be a bit patient.
9 How to enable debug mode for my Android app?
Look for a command named adb in your SDK package. Run adp -logcat to get logs.
Log class is for this purpose. Print out log messages with Log.i() or e() or d() etc.
10 How do I install an application into my emulator?
Use adb available in your sdk or compiled android kernel (out/host/yourplatform/bin).
./adb shell is always a good starting point. To install an application from apk file
./adb install /path/to/YourApp.apk
Use -r for reinstallation. There's also an alternative here .
11 I am using eclipse android plugin, where do I see my android sdk location?
You guessed it, preferences->android.
12 How do I uninstall apps from my emulator?
Go to your sdk home directory, cd tools, run ./emulator -wipe-data.
13 I don't have a data plan, how do I register my phone with google so I can use my wifi?
If you have a dev phone, you could use the adb tools. Refer to http://blog.technomancy.org/2009/1/14/how-to-register-an-android-dev-g1-over-wifi . Otherwise, you could buy a pre-paid card from a carrier to do the job.
14 Android Java virtual machine
Although Android is using Java, it's not using Sun mobile JVM, even the Android byte code format is different
15 How do I check my CPU information
Install SDK, or download android source code and build from scratch. You'll have adb SDK_HOME/tools or our/host/xxx/bin. Then
mikes-macbook:tools mike$ adb shell
$ su
# cat /proc/cpuinfo
Processor : ARMv6-compatible processor rev 2 (v6l)
BogoMIPS : 245.36
Features : swp half thumb fastmult edsp java
CPU implementer : 0x41
CPU architecture: 6TEJ
CPU variant : 0x1
CPU part : 0xb36
CPU revision : 2
Cache type : write-back
Cache clean : cp15 c7 ops
Cache lockdown : format C
Cache format : Harvard
I size : 32768
I assoc : 4
I line length : 32
I sets : 256
D size : 32768
D assoc : 4
D line length : 32
D sets : 256
Hardware : trout
Revision : 0080
Serial : xxxxxxxxxxxxxxxxxx
16 How do I insert pause?
Use , (comma). One , equals 2 seconds. # would be followed by a , too. Otherwise it will break.
17 How to give more storage space to my apps?
17.1 Ultimate solution: install apps on sd card (not successful on recent 1.1 firmware, work on custom builds shown below)
A few concerns [GG]
Security: if apps on SD card is allowed to do something, chances are people may insert a chip and do something bad to your system?? Also, the fs is set to be FAT so users can plug their card to PCs and use them.
Integrity: what happens if sd cards are pulled out, replaced etc.
Licensing: what happens if user buy app from one phone, install it on sd card, and put the sd in another phone. Or even worse, copy it to another sd card.
People have proposed a workaround . Have yet to try this. Another contributor has packaged this into an update.zip .
Getting root and read/write access , How to root your gphone
Format your microSD card with one FAT and one ext2. In my case, I had to use killdisk to kill the microSD,
then use osX to split it into two different partitions, and then use my Ubutuntu VM to format them into
a FAT32 volume (mkfs.vfat -F 32 /dev/sdb1) and an ext2 volume (mkfs.ext2 /dev/sdb2).
./adb shell
$ su
# ./adb pull /init.rc ./bak/init.rc
# ./adb pull /system/etc/mountd.conf ./bak/mountd.conf
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/ If you get "permission denied error"[RA]
17.2 Move application cache to sdcard
This is easier and works for all version. You could do this without busybox , however, things would be much easier with it.
To checkout how much storage space each app is using, cd /data/data/, do a "busybox du -ks *". For example, browser always takes a lot of storage space, then you can put browser cache into /sdcard with the following commands[AC] :
#mkdir /sdcard/cache
#mkdir /sdcard/cache/browser
#rm -rf /data/data/com.android.browser/cache
#ln -s /sdcard/cache/browser /data/data/com.android.browser/cache
Note the security implication of doing this: since /sdcard is only a fat file system, any app can check out your browsing history if it wants to.
18 Only the original thread that created a view hierarchy can touch its views.
Use Handler and Message instead.
19 How do android keep the screen on?
setKeepScreenOn(true)
20 java.lang.SecurityException: Requires VIBRATE permission
In your AndroidManifest.xml, add the following at top level (same level with <application> tags.
<uses-permission android:name="android.permission.VIBRATE"/>
21 References
22 How do I use android to tether?
If you have root access (for example, if you have an unlocked phone, or a dev phone), look for a free application called "Wifi Tethering for Root User". Or download from this link just in case something happens to it.
An alternative is ad hoc wifi tether app
http://code.google.com/p/android-wifi-tether/
23 How to check the list of apps I ran?
Press and hold home key
24 How do I use android default icons?
Look at http://developer.android.com/reference/android/R.drawable.html . For example, you could use this icon in your menus:
menu.add(0, 1000, 0, "Setup").setIcon(android.R.drawable.ic_menu_preferences);
25 How do I download a specific patch?
use repo download, for example,
repo download platform/frameworks/base 9300
26 What's cupcake?
Cupcake is a work-in-progress read-only dev branch. [CC]
27 Pair with a bluetooth device?
Settings->wireless->bluetooth. Put your headset in "pair mode", and press menu button on your android to start searching. Once you find your device, pair it. If asked for password, input 0000 or look for the code in your manual/online. You can only use your bluetooth headset for phone calls. Wont' work with music etc.
28 How do I put my android app into full screen mode?
this.requestWindowFeature(Window.FEATURE_NO_TITLE)
this.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
29 What is yaffs?
YAFFS (Yet Another Flash File System).
30 Is there an adb-client-like application
Search terminal emulator in android market.
31 Android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xxxx.bbb/YourAction}; have you declared this activity in your AndroidManifest.xml?
Add this to your AndroidManifest.xml
...
<application...>
...
<activity android:name="YourActivity" android:label="@string/your_activity_title" />
</application>
32 How do I create settings like settings in standard Android apps like Calendar etc?
First, create res/xml/preferences.xml like the following:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/preferences_screen_size_title">
<ListPreference
android:key="preferences_screen_size"
android:defaultValue="@string/preferences_screen_size_default"
android:title="@string/preferences_screen_size_title"
android:entries="@array/preferences_screen_size_labels"
android:entryValues="@array/preferences_screen_size_values"
android:dialogTitle="@string/preferences_screen_size_diaglog" />
</PreferenceCategory>
</PreferenceScreen>
Adjust string/array value names based on your needs
Then, define corresponding string/array variables in res/values/arrays.xml
and res/values/strings.xml, for example, in strings.xml
<string name="preferences_screen_size_title">Screen Size</string>
and arryas.xml
<resources>
<string-array name="preferences_screen_size_labels">
<item>3 by 4</item>
<item>6 by 8</item>
<item>9 by 12</item>
</string-array>
<string-array name="preferences_screen_size_values" translatable="false">
<item>"3x4"</item>
<item>"6x8"</item>
<item>"9x12"</item>
</string-array>
</resources>
Then create an Action class like the following:
public class YourPreferences extends PreferenceActivity
implements OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.preferences);
PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
screenSize = (ListPreference) preferenceScreen.findPreference(KEY_SCREEN_SIZE);
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals(KEY_SCREEN_SIZE)) {
//set screen size
}
}
}
At last, add the following code when you need to trigger the settings windows:
Intent intent = new Intent();
intent.setType(Intent.ACTION_VIEW);
intent.setClassName(this, YourPreferences.class.getName());
this.startActivity(intent);
33 Why is the default value of my ListPreferences not set properly?
Make sure you have quotes when you define your list in res/values/arrays.xml, but no quotes when you define android:defaultValue.
34 What is G1 phone screen resolution?
320x480
35 How to handle screen orientation?
[DX]
In your AndroidManifest.xml file, your android:screenOrientation can have these different values:
unspecified: No preference specified: let the system decide the best orientation. This will either be the orientation selected by the activity below, or the user's preferred orientation if this activity is the bottom of a task. If the user explicitly turned off sensor based orientation through settings sensor based device rotation will be ignored. If not by default sensor based orientation will be taken into account and the orientation will changed based on how the user rotates the device
landscape Would like to have the screen in a landscape orientation: that is, with the display wider than it is tall.
portrait Would like to have the screen in a portrait orientation: that is, with the display taller than it is wide.
user Use the user's current preferred orientation of the handset.
behind Keep the screen in the same orientation as whatever is behind this activity.
sensor Orientation is determined by a physical orientation sensor: the display will rotate based on how the user moves the device.
nosensor Always ignore orientation determined by orientation sensor: tthe display will not rotate when the user moves the device.
*
If used programmatically, you could use the following constants: ActivityInfo.CREEN_ORIENTATION_BEHIND SCREEN_ORIENTATION_LANDSCAPE SCREEN_ORIENTATION_NOSENSOR SCREEN_ORIENTATION_PORTRAIT SCREEN_ORIENTATION_SENSOR SCREEN_ORIENTATION_UNSPECIFIED SCREEN_ORIENTATION_USER
To fix your activity to an orientation
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
Control your screen with orientation sensor, so it flips automatically
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="sensor">
Disable automatic activity destory/recreate when you show/hide keyboard
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
For more info on configChanges, refer to Configuration and onConfigurationChange
Programmatically:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
36 How to define size of a View with number of pixels in layout xml file?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal" >
37 How do I get a View in res/layout by its ID?
TextView titleTextView = (TextView) this.activity.findViewById(R.id.titleText);
[AD]
38 How do I save data to files?
http://developer.android.com/guide/topics/data/data-storage.html
39 How come I dont' see android device on my Ubuntu when I run adb -devices?
Try creating a file called /etc/udev/rules.d/50-android.rules and
plugging the following line into it:
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
Reload udev's configuration (/etc/init.d/udev reload)[AG]
40 How do I uninstall apps with adb?
./adb uninstall com.rule55.packagename (with Activity name omitted)
41 How do I make my app automatically change orientation?
Use android:screenOrientation="sensor" in your AndroidManifest.xml file, for example:
<activity android:name=".YourName"
android:screenOrientation="sensor"
android:label="@string/app_name">
42 How do I add a ProgressBar to my app?
<ProgressBar id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
[VG]
43 How do I use g-phone as a music player?
Use the Music app that comes with the phone. To copy music to your phone, create a directory called music on /sdcard (actually it could be named anything), and copy your mp3 files into that directory.
44 How about the usb charger?
The port on the g-phone is actually a standard usb port: among all the standard usb connector types, it uses the mini-B connector. For example, the charger cable uses mini-B on the phone side, and type-A on the computer side. The earphone, however, only has one usb connector, and it uses mini-B connector. [WP]
45 How do I install/enable Google Chinese Pinyin on Android 1.5 (cupcake)?
Either download precompiled Google Pinyin IME to your computer and user adb to install it. Or you could enable settings->application->Allow unknown source, and install from http://www.rule55.com/downloads/PinyinIME.apk directly.
After successful installation, go to settings->Locale, enable Chinese IME *and* disable Android keyboard.[DH]
If you want to compile PinyinIME.apk from the source code:
Get a copy of Android Cupcake source code , if you don't have them already, otherwise go into your Android Cupcake source directory and run "repo sync"
Under your android cupcake source home directory, run "make PinyinIME"
If everything goes on well, you will find PinyinIME.apk under out/target/product/dream/system/app/PinyinIME.apk
46 How do I sign my app?
keytool --genkey -v -keystore ./release-keystore -alias android-release -keyalg RSA -validity 10000
jarsigner -verbose -keystore ./release-keystore yourapp.apk android-release
References [AC] http://androidcommunity.com/forums/f28/updated-move-caches-to-sd-card-11167/ [AD] http://developer.android.com/guide/topics/resources/available-resources.html#dimension [AG] http://groups.google.com/group/android-developers/browse_thread/thread/af53210a9c41ec37/a0abc58971a44ac0f [AW] http://source.android.com/download [BS] http://honeypod.blogspot.com/2007/12/compile-android-kernel-from-source.html [CC] http://source.android.com/roadmap/cupcake [DH] http://blog.douhua.im/2009/05/24/android-adp1-google-pinyin/ [DX] http://www.devx.com/wireless/Article/40792/1763/page/5 [GG] http://groups.google.com/group/android-platform/browse_thread/thread/f16154436e203b11?pli=1 [RA] http://android-dls.com/wiki/index.php?title=Rooting_Android [VG] http://www.droiddraw.org/widgetguide.html [WP] http://en.wikipedia.org/wiki/USB