Sign in Join
Wiki copytemporary

Android Programming/zh CN: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11其它请参考 [[Custom Drawn Interface/Android]]
22
33了解普通的Android 程序开发可以非常有用的帮助Lazarus Android界面的开发。
44
55## 如何做...
66
77### 构建 NDK OpenGL 示例
88
99操作步骤如下:
1010
1111**第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]]
1212
1313**第2步** - 安装已经编译好的FPC跨平台编译器. 说明信息在这儿: [[Android Interface|Android_Interface#Using_the_pre-compiled_compiler]]
1414
1515**第3步** - 下载最新的 lazarus-ccr sourceforge 代码:
1616
17-```
17+```text
1818svn co https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr lazarus-ccr
1919```
2020
2121或者如果你觉得这个文件夹太大那么你可以只下载此文件夹 lazarus-ccr/bindings/android-ndk
2222
2323**第4步** - 构建Pascal库文件(.SO)
2424
2525打开工程 lazarus-ccr/bindings/android-ndk/examples/opengltest/opengltest.lpi
2626
2727然后打开菜单 Project-\>Project Options-\>Paths 和右边的 "Libraries -Fl" 你可以看到如下所示:
2828
29-```
29+```text
3030/home/felipe/Programas/android-ndk-r5/platforms/android-9/arch-arm/usr/lib
3131```
3232
3333更改Android NDK路径为你的电脑中Andorid NDK的路径, 并且更改最低需要的Android API版本库文件夹路径为你的电脑的路径.
3434
3535现在使用Lazarus构建工程.
3636
3737**第5步** - 配置构建环境变量
3838
3939打开文件 opengltest/local.properties 查看这一行:
4040
41-```
41+```text
4242sdk.dir=/home/felipe/Programas/android-sdk-linux
4343```
4444
4545更改为你的Android SDK的路径, 注意 "/" 和 "\\"的区别
4646
4747**第6步** - 构建 APK 包
4848
4949打开一个终端(命令行)并且输入如下命令:
5050
5151cd lazarus-ccr/bindings/ndk/examples/opengltest/android ant debug
5252
5353成功构建的APK包位于这个文件夹中: opengltest/android/bin/
5454
5555**第7步** - 安装 APK 包
5656
5757如果在这一步你得到关于权限的错误信息,可以阅读这儿: [[Android Interface/Using the Android SDK, Emulator and Phones|Android_Interface/Using_the_Android_SDK%2C_Emulator_and_Phones#Recognition_of_devices_under_Linux]]
5858
5959使用命令行安装我们生成的APK包到手机:
6060
61-```
61+```text
6262cd opengltest/android
6363~/Programas/android-sdk-linux/platform-tools/adb install bin/OpenGLNDKTest-debug.apk
64642395 KB/s (107299 bytes in 0.043s)
6565 pkg: /data/local/tmp/OpenGLNDKTest-debug.apk
6666Success
6767```
6868
6969如果你得到一个包已经安装的错误信息那么你可以使用以下命令来卸载它:
7070
71-```
71+```text
7272~/Programas/android-sdk-linux/platform-tools/adb uninstall com.pascal.opengltest
7373```
7474
7575然后你可以在命令行中运行adb logcat,可以看到这个log记录, 它可以告诉你是如何在手机中添加一个新图标应用的:
7676
77-```
77+```text
7878~/Programas/android-sdk-linux/platform-tools/adb logcat
7979```
8080
8181### 读取屏幕尺寸
8282
8383First fill a TDisplayMetrics with the correct info:
8484
8585``` pascal
8686uses androidutil;
8787
8888var
8989 MyDisplayMetrics: TDisplayMetrics;
9090 Str: string;
9191 //
9292 lHeight, lWidth: Integer;
9393 xdpi, ydpi, lScreenSize: Single;
9494begin
9595 // ..
9696 // Objects
9797
9898 MyDisplayMetrics := TDisplayMetrics.Create;
9999 Activity.getWindowManager().getDefaultDisplay().getMetrics(MyDisplayMetrics);
100100```
101101
102102And then you can read it from the TDisplayMetrics:
103103
104104``` pascal
105105 lHeight := MyDisplayMetrics.heightPixels();
106106 lWidth := MyDisplayMetrics.widthPixels();
107107 xdpi := MyDisplayMetrics.xdpi();
108108 ydpi := MyDisplayMetrics.ydpi();
109109 lScreenSize := sqrt(sqr(lHeight / ydpi) + sqr(lWidth / xdpi));
110110 ldensity := MyDisplayMetrics.density();
111111 ldensityDpi := MyDisplayMetrics.densityDpi();
112112 scaledDensity := MyDisplayMetrics.scaledDensity();
113113```
114114
115115Note 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.
116116
117117## 关于Android 设备的详细描述
118118
119119Since 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).
120120
121121### 智能手机
122122
123123| **Manufacturer** | **Model** | **Android API Name (Build.Model)** | **Processor** | **Android version** | **Multi-touch** | **Comments** |
124124|----|----|----|----|----|----|----|
125125| HTC | Wildfire | HTC Wildfire | armv6 | 2.1=\>2.2 | Yes\|\|- | |
126126| Sony Erricson | Xperia X10 | X10i | armv7 | 1.6=\>2.1 | No\|\|- | |
127127
128128### 平板
129129
130130| **Manufacturer** | **Model** | **Android API Name (Build.Model)** | **Processor** | **Android version** | **Multi-touch** | **Comments** |
131131|----|----|----|----|----|----|----|
132132| Toshiba | Folio 100 Tablet | TOSHIBA_FOLIO_AND_A | armv7 | 2.2 | Yes\|\|- | |
133133
134134### 处理器兼容设备列表(ARMv6 vs ARMv7)
135135
136136**ARMv7 设备列表:**
137137
138138- Advent Vega (P10AN01)
139139- Dell Streak, Streak 7
140140- HTC Desire
141141- HTC Desire Z (T-Mobile G2)
142142- HTC Desire HD
143143- HTC Droid Incredible
144144- HTC EVO 4G, EVO Shift 4G
145145- HTC Glacier (T-Mobile myTouch 4G)
146146- HTC Inspire 4G
147147- HTC Nexus One
148148- HTC Thunderbolt 4G
149149- Huawei Ideos S7
150150- LG Optimus Z
151151- Motorola Atrix 4G
152152- Motorola Bravo
153153- Motorola Cliq 2 - untested
154154- Motorola Defy
155155- Motorola Droid 2, Droid 2 Global
156156- Motorola Droid Pro (Motorola PRO)
157157- Motorola Droid X
158158- Motorola Xoom
159159- POV Mobii Tegra Tablet
160160- Samsung Continuum (i400)
161161- Samsung Galaxy S (i9000, Captivate, Fascinate, Vibrant, Epic 4G)
162162- Samsung Galaxy Tab
163163- Sharp IS03
164164- Sony Ericsson Xperia X10
165165- Toshiba AS100
166166- Viewsonic gTablet
167167- Acer Liquid E
168168- Acer Liquid (Liquid A1)
169169- Archos 101 Internet Tablet
170170- Motorola Charm
171171- Motorola Droid (Milestone)
172172- Samsung Galaxy S 4G
173173- Samsung Nexus S
174174
175175**ARMv6 处理器列表:**
176176
177177- Android SDK emulator
178178- Asus Garmin nuvifone A50 (T-Mobile Garminfone)
179179- Augen GENTouch 78 Tablet
180180- Coby Kyros Internet Tablet (MID7015)
181181- Geeksphone One, Geeksphone Zero
182182- HTC Aria
183183- HTC ChaCha
184184- HTC Dream (T-Mobile G1, Android Dev Phone 1)
185185- HTC Droid Eris
186186- HTC Espresso (T-Mobile myTouch 3G Slide)
187187- HTC Hero (T-Mobile G2 Touch)
188188- HTC Legend
189189- HTC Magic (T-Mobile myTouch 3G, T-Mobile G1 Touch)
190190- HTC Salsa
191191- HTC Tattoo
192192- HTC Wildfire
193193- Huawei Ascend
194194- Huawei Ideos U8150-B (T-Mobile Comet)
195195- Huawei U8110 (T-Mobile Pulse Mini)
196196- Huawei U8230
197197- LG Ally (Apex) (LG VS740)
198198- LG GW620 (Eve, InTouch Max, LinkMe)
199199- LG Optimus, Optimus M, Optimus T, Optimus S, Optimus V
200200- LG Vortex
201201- LG P500
202202- MAG iMiTO iM7
203203- vMAG iMiTO iM7S
204204- Motorola Backflip
205205- Motorola Citrus
206206- Motorola Cliq (MB200)
207207- Motorola Dext
208208- Motorola Devour
209209- Motorola i1
210210- Motorola Spice XT300
211211- Motorola Quench XT5 XT502
212212- Pandigital Novel
213213- Samsung GT-S5570 Galaxy Mini
214214- Samsung i5500 Galaxy 5 (Corby)
215215- Samsung i5700 Galaxy Portal (Spica)
216216- Samsung i5800 Galaxy 3
217217- Samsung i7500 Galaxy
218218- Samsung Intercept
219219- Samsung M900 Moment
220220- Samsung S5830 Galaxy Ace
221221- Samsung Transform
222222- Sanyo ZIO M6000
223223- Sony Ericsson Xperia X8
224224- Sony Ericsson Xperia X10 Mini
225225- Sony Ericsson Xperia X10 Mini Pro
226226- Superpad 10.2" Tablet PC
227227- Viewsonic ViewPad 7 Tablet
228228- Velocity Micro T103 Cruz tablet
229229- Vodafone 845
230230- ZTE Blade
231231
232232### 在手机中播放声音和视频
233233
234234每一个手机都安装有不同的解码器, 这样意味着不同的手机中本地媒体播放器可以播放不同的格式。以下表格列出了哪些格式可以在哪个手机中的媒体播放器中播放:
235235
236236| **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** |
237237|----|----|----|----|----|----|----|----|----|----|----|
238238| Emulator | 1.6 | x | x | x | x | x | x | x | x | OK |
239239| Emulator | 2.1 | x | x | x | x | x | x | x | x | OK |
240240| Nexus One | 2.2 | x | OK | x | OK | x | x | x | x | OK |
241241| HTC Desire | 1.6 | x | OK | x | OK | x | x | x | OK | OK |
242242| Toshiba Folio 100 | 2.2 | x | OK | x | OK | x | x | x | OK | OK |
243243| Xperia X10 | 2.1 | x | OK | x | x | x | x | x | OK | OK |
244244| Xperia X8 | 2.2 | x | OK | x | x | x | x | x | x | OK |
245245| HTC Wildfire | 2.1 | x | OK | x | x | x | x | x | x | OK |
246246| HTC Desire HD | 2.2 | x | OK | x | OK | x | x | x | x | OK |
247247| Galaxy Tab | 2.2 | x | OK | x | x | x | x | x | x | OK |
248248| myPhone A210 | 1.6 | x | OK | x | x | x | x | x | x | OK |
249249| Motorola Milestone | 2.1 | x | OK | x | x | x | x | x | OK | ? |
250250| Milestone 2 | 2.2 | x | OK | x | x | x | x | x | sound-only | OK |
251251
252252## 新建一个Java Android 应用程序
253253
254254这些信息可以帮助用于实现 LCL-CustomDrawn-Android
255255
256256通用指令在这儿: <http://developer.android.com/guide/developing/other-ide.html>
257257
258258### 显示 / 隐藏 虚拟键盘
259259
260260请看这儿: <http://android-codes-examples.blogspot.com/2011/11/show-or-hide-soft-keyboard-on-opening.html>
261261
262262显示虚拟键盘:
263263
264-```
264+```text
265265InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
266266imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
267267```
268268
269269隐藏虚拟键盘:
270270
271-```
271+```text
272272InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
273273imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),0);
274274```
275275
276276## 参考
277277
278278- <http://developer.android.com/guide/developing/other-ide.html>
279279
280280---
281281*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).*
282282Category: Android/zh CN

Back to history