Sign in Join
Wiki copytemporary

Android Programming/zh CN: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Android Programming/zh CN

OldNewLine
1+其它请参考 [[Custom Drawn Interface/Android]]
2+
3+了解普通的Android 程序开发可以非常有用的帮助Lazarus Android界面的开发。
4+
5+## 如何做...
6+
7+### 构建 NDK OpenGL 示例
8+
9+操作步骤如下:
10+
11+**第1步** - 下载和安装Android NDK, Android SDK 和 Ant.更多的信息在这儿: [[Android Interface/Using the Android SDK, Emulator and Phones|Android_Interface/Using_the_Android_SDK%2C_Emulator_and_Phones]]
12+
13+**第2步** - 安装已经编译好的FPC跨平台编译器. 说明信息在这儿: [[Android Interface|Android_Interface#Using_the_pre-compiled_compiler]]
14+
15+**第3步** - 下载最新的 lazarus-ccr sourceforge 代码:
16+
17+`svn co `[`https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr`](https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr)` lazarus-ccr`
18+
19+或者如果你觉得这个文件夹太大那么你可以只下载此文件夹 lazarus-ccr/bindings/android-ndk
20+
21+**第4步** - 构建Pascal库文件(.SO)
22+
23+打开工程 lazarus-ccr/bindings/android-ndk/examples/opengltest/opengltest.lpi
24+
25+然后打开菜单 Project-\>Project Options-\>Paths 和右边的 "Libraries -Fl" 你可以看到如下所示:
26+
27+`/home/felipe/Programas/android-ndk-r5/platforms/android-9/arch-arm/usr/lib`
28+
29+更改Android NDK路径为你的电脑中Andorid NDK的路径, 并且更改最低需要的Android API版本库文件夹路径为你的电脑的路径.
30+
31+现在使用Lazarus构建工程.
32+
33+**第5步** - 配置构建环境变量
34+
35+打开文件 opengltest/local.properties 查看这一行:
36+
37+`sdk.dir=/home/felipe/Programas/android-sdk-linux`
38+
39+更改为你的Android SDK的路径, 注意 "/" 和 "\\"的区别
40+
41+**第6步** - 构建 APK 包
42+
43+打开一个终端(命令行)并且输入如下命令:
44+
45+cd lazarus-ccr/bindings/ndk/examples/opengltest/android ant debug
46+
47+成功构建的APK包位于这个文件夹中: opengltest/android/bin/
48+
49+**第7步** - 安装 APK 包
50+
51+如果在这一步你得到关于权限的错误信息,可以阅读这儿: [[Android Interface/Using the Android SDK, Emulator and Phones|Android_Interface/Using_the_Android_SDK%2C_Emulator_and_Phones#Recognition_of_devices_under_Linux]]
52+
53+使用命令行安装我们生成的APK包到手机:
54+
55+`cd opengltest/android`\
56+`~/Programas/android-sdk-linux/platform-tools/adb install bin/OpenGLNDKTest-debug.apk `\
57+`2395 KB/s (107299 bytes in 0.043s)`\
58+`       pkg: /data/local/tmp/OpenGLNDKTest-debug.apk`\
59+`Success`
60+
61+如果你得到一个包已经安装的错误信息那么你可以使用以下命令来卸载它:
62+
63+`~/Programas/android-sdk-linux/platform-tools/adb uninstall com.pascal.opengltest`
64+
65+然后你可以在命令行中运行adb logcat,可以看到这个log记录, 它可以告诉你是如何在手机中添加一个新图标应用的:
66+
67+`~/Programas/android-sdk-linux/platform-tools/adb logcat`
68+
69+### 读取屏幕尺寸
70+
71+First fill a TDisplayMetrics with the correct info:
72+
73+``` pascal
74+uses androidutil;
75+
76+var
77+ MyDisplayMetrics: TDisplayMetrics;
78+ Str: string;
79+ //
80+ lHeight, lWidth: Integer;
81+ xdpi, ydpi, lScreenSize: Single;
82+begin
83+ // ..
84+ // Objects
85+
86+ MyDisplayMetrics := TDisplayMetrics.Create;
87+ Activity.getWindowManager().getDefaultDisplay().getMetrics(MyDisplayMetrics);
88+```
89+
90+And then you can read it from the TDisplayMetrics:
91+
92+``` pascal
93+ lHeight := MyDisplayMetrics.heightPixels();
94+ lWidth := MyDisplayMetrics.widthPixels();
95+ xdpi := MyDisplayMetrics.xdpi();
96+ ydpi := MyDisplayMetrics.ydpi();
97+ lScreenSize := sqrt(sqr(lHeight / ydpi) + sqr(lWidth / xdpi));
98+ ldensity := MyDisplayMetrics.density();
99+ ldensityDpi := MyDisplayMetrics.densityDpi();
100+ scaledDensity := MyDisplayMetrics.scaledDensity();
101+```
102+
103+Note that lots of devices lie about the xdpi and ydpi, so don't trust the lScreenSize calculated above. Smartphones might report even 10 inches of screen size, while the correct is around 4.
104+
105+## 关于Android 设备的详细描述
106+
107+Since there are so many Android devices, it can be useful to keep track of some information about them. See also in the wikipedia Comparison of Android Devices [1](http://en.wikipedia.org/wiki/Comparison_of_Android_devices) and details about the processors in [2](https://wiki.mozilla.org/Mobile/Platforms/Android#System_Requirements).
108+
109+### 智能手机
110+
111+| **Manufacturer** | **Model** | **Android API Name (Build.Model)** | **Processor** | **Android version** | **Multi-touch** | **Comments** |
112+|----|----|----|----|----|----|----|
113+| HTC | Wildfire | HTC Wildfire | armv6 | 2.1=\>2.2 | Yes\|\|- | |
114+| Sony Erricson | Xperia X10 | X10i | armv7 | 1.6=\>2.1 | No\|\|- | |
115+
116+### 平板
117+
118+| **Manufacturer** | **Model** | **Android API Name (Build.Model)** | **Processor** | **Android version** | **Multi-touch** | **Comments** |
119+|----|----|----|----|----|----|----|
120+| Toshiba | Folio 100 Tablet | TOSHIBA_FOLIO_AND_A | armv7 | 2.2 | Yes\|\|- | |
121+
122+### 处理器兼容设备列表(ARMv6 vs ARMv7)
123+
124+**ARMv7 设备列表:**
125+
126+- Advent Vega (P10AN01)
127+- Dell Streak, Streak 7
128+- HTC Desire
129+- HTC Desire Z (T-Mobile G2)
130+- HTC Desire HD
131+- HTC Droid Incredible
132+- HTC EVO 4G, EVO Shift 4G
133+- HTC Glacier (T-Mobile myTouch 4G)
134+- HTC Inspire 4G
135+- HTC Nexus One
136+- HTC Thunderbolt 4G
137+- Huawei Ideos S7
138+- LG Optimus Z
139+- Motorola Atrix 4G
140+- Motorola Bravo
141+- Motorola Cliq 2 - untested
142+- Motorola Defy
143+- Motorola Droid 2, Droid 2 Global
144+- Motorola Droid Pro (Motorola PRO)
145+- Motorola Droid X
146+- Motorola Xoom
147+- POV Mobii Tegra Tablet
148+- Samsung Continuum (i400)
149+- Samsung Galaxy S (i9000, Captivate, Fascinate, Vibrant, Epic 4G)
150+- Samsung Galaxy Tab
151+- Sharp IS03
152+- Sony Ericsson Xperia X10
153+- Toshiba AS100
154+- Viewsonic gTablet
155+- Acer Liquid E
156+- Acer Liquid (Liquid A1)
157+- Archos 101 Internet Tablet
158+- Motorola Charm
159+- Motorola Droid (Milestone)
160+- Samsung Galaxy S 4G
161+- Samsung Nexus S
162+
163+**ARMv6 处理器列表:**
164+
165+- Android SDK emulator
166+- Asus Garmin nuvifone A50 (T-Mobile Garminfone)
167+- Augen GENTouch 78 Tablet
168+- Coby Kyros Internet Tablet (MID7015)
169+- Geeksphone One, Geeksphone Zero
170+- HTC Aria
171+- HTC ChaCha
172+- HTC Dream (T-Mobile G1, Android Dev Phone 1)
173+- HTC Droid Eris
174+- HTC Espresso (T-Mobile myTouch 3G Slide)
175+- HTC Hero (T-Mobile G2 Touch)
176+- HTC Legend
177+- HTC Magic (T-Mobile myTouch 3G, T-Mobile G1 Touch)
178+- HTC Salsa
179+- HTC Tattoo
180+- HTC Wildfire
181+- Huawei Ascend
182+- Huawei Ideos U8150-B (T-Mobile Comet)
183+- Huawei U8110 (T-Mobile Pulse Mini)
184+- Huawei U8230
185+- LG Ally (Apex) (LG VS740)
186+- LG GW620 (Eve, InTouch Max, LinkMe)
187+- LG Optimus, Optimus M, Optimus T, Optimus S, Optimus V
188+- LG Vortex
189+- LG P500
190+- MAG iMiTO iM7
191+- vMAG iMiTO iM7S
192+- Motorola Backflip
193+- Motorola Citrus
194+- Motorola Cliq (MB200)
195+- Motorola Dext
196+- Motorola Devour
197+- Motorola i1
198+- Motorola Spice XT300
199+- Motorola Quench XT5 XT502
200+- Pandigital Novel
201+- Samsung GT-S5570 Galaxy Mini
202+- Samsung i5500 Galaxy 5 (Corby)
203+- Samsung i5700 Galaxy Portal (Spica)
204+- Samsung i5800 Galaxy 3
205+- Samsung i7500 Galaxy
206+- Samsung Intercept
207+- Samsung M900 Moment
208+- Samsung S5830 Galaxy Ace
209+- Samsung Transform
210+- Sanyo ZIO M6000
211+- Sony Ericsson Xperia X8
212+- Sony Ericsson Xperia X10 Mini
213+- Sony Ericsson Xperia X10 Mini Pro
214+- Superpad 10.2" Tablet PC
215+- Viewsonic ViewPad 7 Tablet
216+- Velocity Micro T103 Cruz tablet
217+- Vodafone 845
218+- ZTE Blade
219+
220+### 在手机中播放声音和视频
221+
222+每一个手机都安装有不同的解码器, 这样意味着不同的手机中本地媒体播放器可以播放不同的格式。以下表格列出了哪些格式可以在哪个手机中的媒体播放器中播放:
223+
224+| **Telephone** | **Android** | **webm - VP8** | **m4v - H.264** | **ogv - Theora** | **mp4 - H.264** | **mov - H.264** | **avi - RLE** | **mpg - MPEG-1** | **wmv - WM9** | **3gp - MPEG-4** |
225+|----|----|----|----|----|----|----|----|----|----|----|
226+| Emulator | 1.6 | x | x | x | x | x | x | x | x | OK |
227+| Emulator | 2.1 | x | x | x | x | x | x | x | x | OK |
228+| Nexus One | 2.2 | x | OK | x | OK | x | x | x | x | OK |
229+| HTC Desire | 1.6 | x | OK | x | OK | x | x | x | OK | OK |
230+| Toshiba Folio 100 | 2.2 | x | OK | x | OK | x | x | x | OK | OK |
231+| Xperia X10 | 2.1 | x | OK | x | x | x | x | x | OK | OK |
232+| Xperia X8 | 2.2 | x | OK | x | x | x | x | x | x | OK |
233+| HTC Wildfire | 2.1 | x | OK | x | x | x | x | x | x | OK |
234+| HTC Desire HD | 2.2 | x | OK | x | OK | x | x | x | x | OK |
235+| Galaxy Tab | 2.2 | x | OK | x | x | x | x | x | x | OK |
236+| myPhone A210 | 1.6 | x | OK | x | x | x | x | x | x | OK |
237+| Motorola Milestone | 2.1 | x | OK | x | x | x | x | x | OK | ? |
238+| Milestone 2 | 2.2 | x | OK | x | x | x | x | x | sound-only | OK |
239+
240+## 新建一个Java Android 应用程序
241+
242+这些信息可以帮助用于实现 LCL-CustomDrawn-Android
243+
244+通用指令在这儿: <http://developer.android.com/guide/developing/other-ide.html>
245+
246+### 显示 / 隐藏 虚拟键盘
247+
248+请看这儿: <http://android-codes-examples.blogspot.com/2011/11/show-or-hide-soft-keyboard-on-opening.html>
249+
250+显示虚拟键盘:
251+
252+`InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);`\
253+`imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);`
254+
255+隐藏虚拟键盘:
256+
257+`InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);`\
258+`imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),0);`
259+
260+## 参考
261+
262+- <http://developer.android.com/guide/developing/other-ide.html>
263+
264+---
265+*From the Free Pascal wiki, page "Android Programming/zh CN", as it stood on 2020-02-09 after a change by GAN, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
266+Category: Android/zh CN

Back to history