2014年1月19日 星期日

從html上截取JSON出現轉換錯誤...


需求:從HTML上截取內容轉換為JSONObject
使用方式如下:

JSONObject json = new JSONObject(html);

卻出現exception:
 org.json.JSONException: Value  of type java.lang.String cannot be converted to JSONObject


解決:
 我遇到的問題是,此截取的html為UTF-8編碼,因此開頭出現了UTF-8編碼字元如下圖:
而我存取的這個html存檔類型為UTF-8,最後我使用nopad++將檔案另外保存為『檔首無BOM』的形式就可以了.

使用nopad++『編輯』->『編譯成UTF-8碼(檔首無BOM)』

2014年1月3日 星期五

Android - 如何讓安裝的APP不出現在手機的『程式列表』中( all apps list)

參考:Display message after Package install
         Creating a Main Activity which DOES NOT appear in the launcher list

需求:之前客戶有提出,希望有一個APP為主體,這裡稱之為MAIN_APP,然後之後其他安裝附屬APP(B_APP,C_APP...)都是一定要靠MAIN_APP才能啟動,且不能讓這些其他已安裝的APP顯示在『程式列表』中:


解法:
  其實很簡單,只要將
            
                
                
            

改為:
            
                

                
            

也就是說將原先的android.intent.category.LAUNCHER替換為android.intent.category.INFO就可以囉

android.intent.category.LAUNCHER我們都清楚是幹嘛的,至於android.intent.category.INFO是做什麼的呢?以下截取自官方DOC:

Provides information about the package it is in; typically used if a package does not contain a CATEGORY_LAUNCHER to provide a front-door to the user without having to be shown in the all apps list.
Constant Value: "android.intent.category.INFO"

而依照此篇文章所說,如果要讓googl play這些附屬APP(B_APP,C_APP...)的google play專屬頁也要能顯示『開啟』按鈕,似乎就是得靠加上

<action android:name="android.intent.action.MAIN" />來幫忙,不過這部分我還沒測試過,之後測試過再確定更新吧(希望我還記得...)