2013年10月16日 星期三

Application Cannot Launch From Eclipse

當程式要測試時出現 ActivityManager: java.lang.SecurityException: Permission Denial
且程式無法自動跑起來。

有兩種可能性:

  1. 重複定義了兩個 Launcher 的 Activity 在 AndroidManifest.xml,如:連結
    拿掉其中一個定義即可。
  2. 修改了 Launcher 沒有 Clean ,導致 Launcher 不合。
    Refresh、Clean 過重新執行即可。


2013年10月7日 星期一

Genymotion Multi Touch On MacOSX

在 Mac 版的 Genymotion 的多點觸控用法為

  • 縮放:放大 Ctrl + 左鍵按下往左拖,縮小 Ctrl + 左鍵按下往右拖
    • Zoom In:Ctrl + Mouse Drag Left
    • Zoom Out:Ctrl + Mouse Drag Right
  • 俯角:前傾 Ctrl + 左鍵按下往上拖,後傾 Ctrl + 左鍵按下往下拖
    • Tilt Forth:Ctrl + Mouse Drag Up
    • Tilt Back:Ctrl + Mouse Drag Down
  • 旋轉:逆時鐘旋轉 Ctrl + Shift + 左鍵按下往左拖,順時鐘旋轉 Ctrl + Shift + 左鍵按下往右拖
    • Counterclockwise Rotation:CTRL + Shift + Mouse Drag Left
    • Clockwise Rotation:CTRL + Mouse Drag Right

2013年10月1日 星期二

Eclipse Trace Code Tips On OSX

以 OSX 上的 Eclipse Java Editor 為例
記錄一下裡面常用的一些預設熱鍵

1. 檔案管理

重新整理:F5
關閉目前檔案:Command + W
關閉全部檔案:Command + Shift + W
儲存目前檔案:Command + S

2. 編輯

自動補完:Option + /
修正錯誤提示:Command + 1
重新命名變數或函式:Command + 2 然後按 R
註解單行:Command + /
刪除單行:Command + D

2.1 游標

移到行首:Command + ←
移到行末:Command + →

3. 瀏覽

跳到該變數或函式的定義:Command + 滑鼠左鍵
跳到上一個看的位置:Command + [
跳到下一個看的位置:Command + ]

查詢變數或函式上的引用地方:Command + Shift + G
查詢 Class 繼承:Command + T



同場加映大抄:http://isagoksu.com/2009/development/developer-tools/dislikes/eclipse/osx-keyboard-binding-cheat-sheet/

2013年8月27日 星期二

ClassNotFoundException After Update Android SDK Tool Update To v22.0.x

很多人升上 Android SDK Tools v22.x.x 以後,原本可以執行的專案就會遇到 ClassNotFoundException,但是明明就可以 Build 起來。

這時候就要去 Build Path 的 Order and Export 裡面將 Android Private Libraries 勾起來。

2013年8月8日 星期四

Android Change android:installLocation From auto To preferExternal

在 AndroidManifest.xml 內的安裝位置原本無設定,更新成有設為 preferExternal 的版本在重開機以後會讓 App 消失。
步驟如下:

  1. 安裝舊版
  2. 打開 App,確認正常
  3. 重開機
  4. 打開 App 確認依然正常
  5. 安裝新版 App
  6. 打開 App 確認正常
  7. 重開機
目前已知手機會出現此問題手機有:

  • Galaxy Note (GT-N7000)
  • Sony xperia s LT26i
  • Galaxy S II (GT-I9100)
相關 Issue:https://code.google.com/p/android/issues/detail?id=56038

2013年7月21日 星期日

Git Diff Changed File Between Two Commit

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT COMMIT1 COMMIT2

將其中的 commit1 和 2 換成想比較的兩個 commit 即可。


如果只想複製出有更新的檔案
cp $(git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT COMMIT1 COMMIT2) PATH_TO_TARGET

Android Scan File Cause Global Reference Table Overflow (max=51200)

Android 4.x (版本不確定,已知版本 4.1.1、4.2.2),如果極端大量且快速的執行寫檔後馬上 scanFile 的動作,會造成 JNI ERROR (app bug): global reference table overflow (max=51200),詳細原因見官方 Issue:Issue 53914

如果遇到這種問題,就在最後再執行一次完整 scanFile 避掉,而非每存一個檔案就進行一次 scanFile 。

2013年7月17日 星期三

Android Context.startActivity From Uri Must Catch ActivityNotFoundException

如果 Intent 是用 Uri.parse 出的,在 startActivity 時請一定要 try catch ActivityNotFoundException。

例如:大部分的 Android 裝置都會有 Google Play,但是有些可能是白牌手機之類的,這時候如果想要去呼叫 Google Play 就會出現 ActivityNotFoundException。

所以如果不想管這麼多,就是只要用 Uri 或甚至是 package name 去 startActivity 的都要處理,除非有先用其他方式檢查過要開到的 Activity 是否存在。

2013年7月16日 星期二

Android Notification PendingIntent Received Old Intent

在 Android 中遇到點了 Notification 但是 Activity 卻的 onNewIntent 收到舊的 Intent 的狀況。

有兩種解法,各有各的用途和適合情況。

1. 在 PendingIntent.getActivity(context, requestCode, intent, flag) 的 flag 傳入 PendingIntent.FLAG_UPDATE_CURRENT

這種作法會在 requestCode 相同,但收到多個 Notification 時,只會保留最後的 PendingIntent。
官方文件說 requestCode 沒有用到是騙~人~的!
適合用在如只需要保留最後最新的資訊用到。

2. 在 PendingIntent.getActivity(context, requestCode, intent, flag) 的 requestCode 傳入 count

這個 count 是用來計算這是發第幾個通知。通常會和 NotificationManager.notify(count, pendingIntent) 用同一個。
這適合用在每則通知都要傳入不同的通知訊息內容時使用。

2013年7月4日 星期四

GenyMotion - The Faster Android Emulator


GenyMotion 是一個 Android 的模擬器,不像 Google 提供的慢吞吞模擬器,速度快很多。
裡面的映像檔有提供諸如:Nexus One、Nexus S、Galaxy Nexus、Nexus 7...等等各種尺寸的映像檔。也有 Google Play 可以讓你下載程式回來用,換句話說測試或是想拿來轉轉神魔之塔也可以用這個。
目前還沒開始收費。
安裝方式:
1. 先下載安裝 Virtual Box 的 MacOS 版,官網:https://www.virtualbox.org/wiki/Downloads
2. 下載安裝 GenyMotion,官網:https://cloud.genymotion.com/
註冊時,這個帳號之後用來下載映像檔也會用到。

Have a nice emulator :p