2016年10月22日 星期六

[Android]記憶卡容量?


import android.os.Environment;
import android.os.StatFs;


    /* 判斷記憶卡是否插入 */
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
    {
      /* 取得SD CARD檔案路徑一般是/sdcard */
      File path = Environment.getExternalStorageDirectory();

      /* StatFs看檔案系統空間使用狀況 */
      StatFs statFs = new StatFs(path.getPath());
      /* Block的size */
      long blockSize = statFs.getBlockSize();
      /* 總Block數量 */
      long totalBlocks = statFs.getBlockCount();
      /* 已使用的Block數量 */
      long availableBlocks = statFs.getAvailableBlocks();

      String[] total = fileSize(totalBlocks * blockSize);
      String[] available = fileSize(availableBlocks * blockSize);

      ...

    } else if (Environment.getExternalStorageState().equals(
        Environment.MEDIA_REMOVED))
    {
      String text = "SD CARD已移除";
      ...
    }
  }


2016年10月17日 星期一

[Android] Android APP內嵌WebView , 連結時會跳轉Browser,Why?



要解決跳轉問題,webview必須執行setWebViewClient :


                webview.setWebViewClient(new WebViewClient() {
                    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                        Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                        super.onReceivedError(view, request, error);
                    }
                });




記得增加下列權限,否則可能出現 NET::ERR_CACHE_MISS 錯誤:
<uses-permission android:name="android.permission.INTERNET" />


reference : http://jianworks.blogspot.tw/2014/12/android-webview-neterrcachemiss.html

2016年10月16日 星期日

[Blog] 如何在 Blogger 上建立 code block 程式碼顯示區塊

reference : http://chiumog.blogspot.tw/2015/02/blog-code-block.html
reference : http://jeffyon.blogspot.tw/2012/01/blogger-code-block.html


在 Blog 上套用 CSS :

CODE {
    display: block; /* fixes a strange ie margin bug */
    font-family: Courier New;
    font-size: 8pt;
    overflow:auto;
    background: #f0f0f0 url(http://klcintw.images.googlepages.com/Code_BG.gif) left top repeat-y;
    border: 1px solid #ccc;
    padding: 10px 10px 10px 21px;
    max-height:200px;
    line-height: 1.2em;
}

在想要的 code 前後加上如下範例:

<pre class="codeblock prettyprint">
<code>
中間可以插入你想放入的程式碼
</code>
</pre>
(如果在 code 中有特殊符號,可使用 HTML Encode 轉換)

[Android Studio] Button的文字內容怎麼變成大寫了?


解決方法就是在Button layout下加入如下:
android:textAllCaps="false"
就像這樣子:
<Button
        android:text="Example1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textAllCaps="false"
        android:id="@+id/Example1" />