網頁

2015年2月6日 星期五

android 語系

1. File/new/Other...
2. Android/Android XML File, 按 Next
3. File: 輸入 strings.xml, Root Element:resources 按 Next
4. 加入 Language:zh
5. 加入 Region:tw
6. Folder: /res/values-zh-rTW
7. 產生 /res/values-zh-rTW/strings.xml


AVD 的鍵盤輸入

進 Eclipse 點 Window/Android Virtual Device Manager
編輯虛擬機器之 Keyboard 設定
勾選 Hardware keyboard present:使用開發機器的實體鍵盤
  可方便輸入英文和符號,但無法使用中文
  原本要按 Shift 的要加按 Alt
取消勾選 Hardware keyboard present:使用Android的鍵盤
  可安裝中文輸入法,但很難操作

下載adnroid注音輸入法

安裝輸入法
C:\eclipse4_64\android-sdk-windows\platform-tools>adb install ZhuYinIME_2010030801.apk
1101 KB/s (1012516 bytes in 0.897s)
        pkg: /data/local/tmp/ZhuYinIME_2010030801.apk
Success

設定輸入法
設定/語言與輸入設定/勾選注音輸入法

點選 edittext 時還是出現英文鍵盤
常按英文鍵盤的空白鍵,此時跳出輸入法切換,選擇注音輸入法
若要回復成英文鍵盤,還是要回設定取消勾選注音輸入法

adnroid adb

查詢連接的裝置
C:\eclipse4_64\android-sdk-windows\platform-tools>adb devices
List of devices attached
emulator-5554   deviceadb shell
指定一台下命令
C:\eclipse4_64\android-sdk-windows\platform-tools>adb -s emulator-5554 shell
root@android:/ #

查詢網路裝置
C:\eclipse4_64\android-sdk-windows\platform-tools>adb shell netcfg
lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:
00:00:00
eth0     UP                                   10.0.2.15/24  0x00001043 52:54:00:
12:34:56
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:
00:00:00

查詢網路裝置設定
C:\eclipse4_64\android-sdk-windows\platform-tools>adb shell ifconfig eth0
eth0: ip 10.0.2.15 mask 255.255.255.0 flags [up broadcast running multicast]

測試網路
C:\eclipse4_64\android-sdk-windows\platform-tools>adb shell ping -c 3 localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.310 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.616 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.338 ms
--- localhost ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 0.310/0.421/0.616/0.139 ms
好像只能用在 localhost 127.0.0.1 10.0.2.2
發現採用 nc(netcat) 命令才可
C:\eclipse4_64\android-sdk-windows\platform-tools>adb shell nc -v www.google.com 80
Connection to www.google.com 80 port [tcp/www] succeeded!
C:\eclipse4_64\android-sdk-windows\platform-tools>adb shell nc -v 192.168.1.72 8080
Connection to 192.168.1.72 8080 port [tcp/webcache] succeeded!


2015年2月4日 星期三

開啟 https,使用 openssl CA

建立CA私鑰
D:\EclipseAndroid\Web>openssl genrsa -out cakey.pem 2048
查看公鑰
D:\EclipseAndroid\Web>openssl rsa -in cakey.pem -pubout -text
生成自簽證書
D:\EclipseAndroid\Web>set OPENSSL_CONF=c:\Program Files (x86)\GnuWin32\share\openssl.cnf
D:\EclipseAndroid\Web>openssl req -new -x509 -key cakey.pem -out cacert.pem -days 3650
Loading 'screen' into random state - done
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:TW
State or Province Name (full name) [Some-State]:Taiwan
Locality Name (eg, city) []:Taichung
Organization Name (eg, company) [Internet Widgits Pty Ltd]:R&D
Organizational Unit Name (eg, section) []:Mark Chen
Common Name (eg, YOUR name) []:Mark Chen
Email Address []:ingrenn@yahoo.com.tw
D:\EclipseAndroid\Web>mkdir demoCA
D:\EclipseAndroid\Web>mkdir demoCA\private
D:\EclipseAndroid\Web>mkdir demoCA\newcerts
在 demoCA 目錄下建立文字檔 index.txt
在 demoCA 目錄下建立文字檔 serial,內容 "00"
D:\EclipseAndroid\Web>copy cakey.pem demoCA\private
D:\EclipseAndroid\Web>copy cacert.pem demoCA
建立給 tomcat 使用的私鑰
D:\EclipseAndroid\Web>openssl genrsa -out tomcat.key 1024
tomcat 客戶端生成證書簽屬請求
D:\EclipseAndroid\Web>openssl req -new -key tomcat.key -out tomcat.csr
Loading 'screen' into random state - done
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:TW
State or Province Name (full name) [Some-State]:Taiwan
Locality Name (eg, city) []:Taichung
Organization Name (eg, company) [Internet Widgits Pty Ltd]:R&D
Organizational Unit Name (eg, section) []:Mark Chen
Common Name (eg, YOUR name) []:localhost因為在本機使用,正式須如:www.domain.com
Email Address []:ingrenn@localhost

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:不要打密碼,不然會失敗
An optional company name []:
D:\EclipseAndroid\Web>openssl ca -in tomcat.csr -out tomcat.crt -days 3655
D:\EclipseAndroid\Web>openssl pkcs12 -export -in tomcat.crt -inkey tomcat.key -out tomcat.p12
Loading 'screen' into random state - done
Enter Export Password:在 tomcat 的 server.xml 設定中要用
Verifying - Enter Export Password:

在 tomcat 的 server.xml 設定中
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
  maxThreads="150" scheme="https" secure="true"
  clientAuth="false" sslProtocol="TLS"
  keystoreFile="D:\EclipseAndroid\Web\tomcat.p12"
  keystoreType="pkcs12" keystorePass="changit"
/>


開啟 IE /網際網路選項/內容/憑證/受信任的跟憑證授信單位/匯入 cacert.pem

如果要將 http 自動轉成 https,在 web.xml 的 <web-app> 中加入下列設定
<!-- Require HTTPS for everything except /img (favicon) and /css. -->
<security-constraint>
  <web-resource-collection>
    <web-resource-name>HTTPSOnly</web-resource-name>
    <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
</security-constraint>
<security-constraint>
  <web-resource-collection>
    <web-resource-name>HTTPSOrHTTP</web-resource-name>
    <url-pattern>*.ico</url-pattern>
    <url-pattern>/img/*</url-pattern>
    <url-pattern>/css/*</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
    <transport-guarantee>NONE</transport-guarantee>
  </user-data-constraint>
</security-constraint>


android 安裝證書
1. copy cakey.pem cakey.cer
2. 將 cakey.cer 證書放到 /storage/sdcard0/Download
3. 設定/安全性/從手機儲存空間安裝


開啟 https

在 命令提示字元下
>"c:\Program Files\Java\jre7\bin\keytool.exe" -genkeypair -alias tomcat -keyalg RSA -keystore keystore.pfx -storetype pkcs12
您的名字與姓氏為何?
  [localhost]:
您的組織單位名稱為何?
  [R&D]:
您的組織名稱為何?
  [Mark Chen]:
您所在的城市或地區名稱為何?
  [tw]:  Taichung
您所在的州及省份名稱為何?
  [taiwan]:
此單位的兩個字母國別代碼為何?
  [tw]:
CN=localhost, OU=R&D, O=Mark Chen, L=Taichung, ST=taiwan, C=tw 正確嗎?


在 tomcat 的 server.xml 中
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
        maxThreads="150" scheme="https" secure="true"
        clientAuth="false" sslProtocol="TLS"
        keystoreFile="D:\EclipseAndroid\Web\keystore.pfx"
        keystoreType="pkcs12" keystorePass="mark1234"
        />

開啟 IE /網際網路選項/內容/憑證/個人/匯入 keystore.pfx


您的名字與姓氏為何?即是CN
其內容必須是網域名稱如 www.host.com.tw 或 localhost

使用 -storetype pkcs12 否則 IE 無法匯入憑證


2015年2月3日 星期二

Eclipse 加入 Web 開發

1. 開啟 Eclipse
2. Menu/Help/Install New Software
3. 選擇 Luna - http://download.eclipse.org/releases/luna
4. 勾選 Web, XML, Java EE and OSGi Enterprise Development
5. 重開 Eclipse
6. Menu/Windows/Preference
7. 選 Server/Runtime Environments, 選擇 Add
8. 選 Apache/Apache Tomcat v6.0
9. 按 Next 設定 Tomcat 安裝路徑
10. New Project 時,選擇 Web/Dynamic Web Project