Sign in Join
Wiki copytemporary

Android Programming/zh CN: what changed

Revision 1 to 2. 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-`svn co `[`https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr`](https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr)` lazarus-ccr`
17+```
18+svn co https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr lazarus-ccr
19+```
1820
1921或者如果你觉得这个文件夹太大那么你可以只下载此文件夹 lazarus-ccr/bindings/android-ndk
2022
2123**第4步** - 构建Pascal库文件(.SO)
2224
2325打开工程 lazarus-ccr/bindings/android-ndk/examples/opengltest/opengltest.lpi
2426
2527然后打开菜单 Project-\>Project Options-\>Paths 和右边的 "Libraries -Fl" 你可以看到如下所示:
2628
27-`/home/felipe/Programas/android-ndk-r5/platforms/android-9/arch-arm/usr/lib`
29+```
30+/home/felipe/Programas/android-ndk-r5/platforms/android-9/arch-arm/usr/lib
31+```
2832
2933更改Android NDK路径为你的电脑中Andorid NDK的路径, 并且更改最低需要的Android API版本库文件夹路径为你的电脑的路径.
3034
3135现在使用Lazarus构建工程.
3236
3337**第5步** - 配置构建环境变量
3438
3539打开文件 opengltest/local.properties 查看这一行:
3640
37-`sdk.dir=/home/felipe/Programas/android-sdk-linux`
41+```
42+sdk.dir=/home/felipe/Programas/android-sdk-linux
43+```
3844
3945更改为你的Android SDK的路径, 注意 "/" 和 "\\"的区别
4046
4147**第6步** - 构建 APK 包
4248
4349打开一个终端(命令行)并且输入如下命令:
4450
4551cd lazarus-ccr/bindings/ndk/examples/opengltest/android ant debug
4652
4753成功构建的APK包位于这个文件夹中: opengltest/android/bin/
4854
4955**第7步** - 安装 APK 包
5056
5157如果在这一步你得到关于权限的错误信息,可以阅读这儿: [[Android Interface/Using the Android SDK, Emulator and Phones|Android_Interface/Using_the_Android_SDK%2C_Emulator_and_Phones#Recognition_of_devices_under_Linux]]
5258
5359使用命令行安装我们生成的APK包到手机:
5460
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`
61+```
62+cd opengltest/android
63+~/Programas/android-sdk-linux/platform-tools/adb install bin/OpenGLNDKTest-debug.apk
64+2395 KB/s (107299 bytes in 0.043s)
65+ pkg: /data/local/tmp/OpenGLNDKTest-debug.apk
66+Success
67+```
6068
6169如果你得到一个包已经安装的错误信息那么你可以使用以下命令来卸载它:
6270
63-`~/Programas/android-sdk-linux/platform-tools/adb uninstall com.pascal.opengltest`
71+```
72+~/Programas/android-sdk-linux/platform-tools/adb uninstall com.pascal.opengltest
73+```
6474
6575然后你可以在命令行中运行adb logcat,可以看到这个log记录, 它可以告诉你是如何在手机中添加一个新图标应用的:
6676
67-`~/Programas/android-sdk-linux/platform-tools/adb logcat`
77+```
78+~/Programas/android-sdk-linux/platform-tools/adb logcat
79+```
6880
6981### 读取屏幕尺寸
7082
7183First fill a TDisplayMetrics with the correct info:
7284
7385``` pascal
7486uses androidutil;
7587
7688var
7789 MyDisplayMetrics: TDisplayMetrics;
7890 Str: string;
7991 //
8092 lHeight, lWidth: Integer;
8193 xdpi, ydpi, lScreenSize: Single;
8294begin
8395 // ..
8496 // Objects
8597
8698 MyDisplayMetrics := TDisplayMetrics.Create;
8799 Activity.getWindowManager().getDefaultDisplay().getMetrics(MyDisplayMetrics);
88100```
89101
90102And then you can read it from the TDisplayMetrics:
91103
92104``` pascal
93105 lHeight := MyDisplayMetrics.heightPixels();
94106 lWidth := MyDisplayMetrics.widthPixels();
95107 xdpi := MyDisplayMetrics.xdpi();
96108 ydpi := MyDisplayMetrics.ydpi();
97109 lScreenSize := sqrt(sqr(lHeight / ydpi) + sqr(lWidth / xdpi));
98110 ldensity := MyDisplayMetrics.density();
99111 ldensityDpi := MyDisplayMetrics.densityDpi();
100112 scaledDensity := MyDisplayMetrics.scaledDensity();
101113```
102114
103115Note 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.
104116
105117## 关于Android 设备的详细描述
106118
107119Since 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).
108120
109121### 智能手机
110122
111123| **Manufacturer** | **Model** | **Android API Name (Build.Model)** | **Processor** | **Android version** | **Multi-touch** | **Comments** |
112124|----|----|----|----|----|----|----|
113125| HTC | Wildfire | HTC Wildfire | armv6 | 2.1=\>2.2 | Yes\|\|- | |
114126| Sony Erricson | Xperia X10 | X10i | armv7 | 1.6=\>2.1 | No\|\|- | |
115127
116128### 平板
117129
118130| **Manufacturer** | **Model** | **Android API Name (Build.Model)** | **Processor** | **Android version** | **Multi-touch** | **Comments** |
119131|----|----|----|----|----|----|----|
120132| Toshiba | Folio 100 Tablet | TOSHIBA_FOLIO_AND_A | armv7 | 2.2 | Yes\|\|- | |
121133
122134### 处理器兼容设备列表(ARMv6 vs ARMv7)
123135
124136**ARMv7 设备列表:**
125137
126138- Advent Vega (P10AN01)
127139- Dell Streak, Streak 7
128140- HTC Desire
129141- HTC Desire Z (T-Mobile G2)
130142- HTC Desire HD
131143- HTC Droid Incredible
132144- HTC EVO 4G, EVO Shift 4G
133145- HTC Glacier (T-Mobile myTouch 4G)
134146- HTC Inspire 4G
135147- HTC Nexus One
136148- HTC Thunderbolt 4G
137149- Huawei Ideos S7
138150- LG Optimus Z
139151- Motorola Atrix 4G
140152- Motorola Bravo
141153- Motorola Cliq 2 - untested
142154- Motorola Defy
143155- Motorola Droid 2, Droid 2 Global
144156- Motorola Droid Pro (Motorola PRO)
145157- Motorola Droid X
146158- Motorola Xoom
147159- POV Mobii Tegra Tablet
148160- Samsung Continuum (i400)
149161- Samsung Galaxy S (i9000, Captivate, Fascinate, Vibrant, Epic 4G)
150162- Samsung Galaxy Tab
151163- Sharp IS03
152164- Sony Ericsson Xperia X10
153165- Toshiba AS100
154166- Viewsonic gTablet
155167- Acer Liquid E
156168- Acer Liquid (Liquid A1)
157169- Archos 101 Internet Tablet
158170- Motorola Charm
159171- Motorola Droid (Milestone)
160172- Samsung Galaxy S 4G
161173- Samsung Nexus S
162174
163175**ARMv6 处理器列表:**
164176
165177- Android SDK emulator
166178- Asus Garmin nuvifone A50 (T-Mobile Garminfone)
167179- Augen GENTouch 78 Tablet
168180- Coby Kyros Internet Tablet (MID7015)
169181- Geeksphone One, Geeksphone Zero
170182- HTC Aria
171183- HTC ChaCha
172184- HTC Dream (T-Mobile G1, Android Dev Phone 1)
173185- HTC Droid Eris
174186- HTC Espresso (T-Mobile myTouch 3G Slide)
175187- HTC Hero (T-Mobile G2 Touch)
176188- HTC Legend
177189- HTC Magic (T-Mobile myTouch 3G, T-Mobile G1 Touch)
178190- HTC Salsa
179191- HTC Tattoo
180192- HTC Wildfire
181193- Huawei Ascend
182194- Huawei Ideos U8150-B (T-Mobile Comet)
183195- Huawei U8110 (T-Mobile Pulse Mini)
184196- Huawei U8230
185197- LG Ally (Apex) (LG VS740)
186198- LG GW620 (Eve, InTouch Max, LinkMe)
187199- LG Optimus, Optimus M, Optimus T, Optimus S, Optimus V
188200- LG Vortex
189201- LG P500
190202- MAG iMiTO iM7
191203- vMAG iMiTO iM7S
192204- Motorola Backflip
193205- Motorola Citrus
194206- Motorola Cliq (MB200)
195207- Motorola Dext
196208- Motorola Devour
197209- Motorola i1
198210- Motorola Spice XT300
199211- Motorola Quench XT5 XT502
200212- Pandigital Novel
201213- Samsung GT-S5570 Galaxy Mini
202214- Samsung i5500 Galaxy 5 (Corby)
203215- Samsung i5700 Galaxy Portal (Spica)
204216- Samsung i5800 Galaxy 3
205217- Samsung i7500 Galaxy
206218- Samsung Intercept
207219- Samsung M900 Moment
208220- Samsung S5830 Galaxy Ace
209221- Samsung Transform
210222- Sanyo ZIO M6000
211223- Sony Ericsson Xperia X8
212224- Sony Ericsson Xperia X10 Mini
213225- Sony Ericsson Xperia X10 Mini Pro
214226- Superpad 10.2" Tablet PC
215227- Viewsonic ViewPad 7 Tablet
216228- Velocity Micro T103 Cruz tablet
217229- Vodafone 845
218230- ZTE Blade
219231
220232### 在手机中播放声音和视频
221233
222234每一个手机都安装有不同的解码器, 这样意味着不同的手机中本地媒体播放器可以播放不同的格式。以下表格列出了哪些格式可以在哪个手机中的媒体播放器中播放:
223235
224236| **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** |
225237|----|----|----|----|----|----|----|----|----|----|----|
226238| Emulator | 1.6 | x | x | x | x | x | x | x | x | OK |
227239| Emulator | 2.1 | x | x | x | x | x | x | x | x | OK |
228240| Nexus One | 2.2 | x | OK | x | OK | x | x | x | x | OK |
229241| HTC Desire | 1.6 | x | OK | x | OK | x | x | x | OK | OK |
230242| Toshiba Folio 100 | 2.2 | x | OK | x | OK | x | x | x | OK | OK |
231243| Xperia X10 | 2.1 | x | OK | x | x | x | x | x | OK | OK |
232244| Xperia X8 | 2.2 | x | OK | x | x | x | x | x | x | OK |
233245| HTC Wildfire | 2.1 | x | OK | x | x | x | x | x | x | OK |
234246| HTC Desire HD | 2.2 | x | OK | x | OK | x | x | x | x | OK |
235247| Galaxy Tab | 2.2 | x | OK | x | x | x | x | x | x | OK |
236248| myPhone A210 | 1.6 | x | OK | x | x | x | x | x | x | OK |
237249| Motorola Milestone | 2.1 | x | OK | x | x | x | x | x | OK | ? |
238250| Milestone 2 | 2.2 | x | OK | x | x | x | x | x | sound-only | OK |
239251
240252## 新建一个Java Android 应用程序
241253
242254这些信息可以帮助用于实现 LCL-CustomDrawn-Android
243255
244256通用指令在这儿: <http://developer.android.com/guide/developing/other-ide.html>
245257
246258### 显示 / 隐藏 虚拟键盘
247259
248260请看这儿: <http://android-codes-examples.blogspot.com/2011/11/show-or-hide-soft-keyboard-on-opening.html>
249261
250262显示虚拟键盘:
251263
252-`InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);`\
253-`imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);`
264+```
265+InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
266+imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
267+```
254268
255269隐藏虚拟键盘:
256270
257-`InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);`\
258-`imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),0);`
271+```
272+InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
273+imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),0);
274+```
259275
260276## 参考
261277
262278- <http://developer.android.com/guide/developing/other-ide.html>
263279
264280---
265281*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).*
266282Category: Android/zh CN

Back to history