Cody Blog

How to use Android Snackbar

I created a small toy to demo Android snackbar featrue, you can find the project on cwliu/Try_Snackbar

snackbar demo

Setup

In app build.gradle, add design support library:

dependencies {
    ...
    compile 'com.android.support:design:22.2.0'
}

Show snackbar

Just like the toast usage,

Snackbar.make(view, "Hello world",Snackbar.LENGTH_LONG).show();

Set snackbar action

snackbar.setAction("Undo", new View.OnClickListener() {
    @Override
    public void onClick(View v) {
       // Do something
    }
});

Integrate snackbar to floating action button

coordinator_layout = findViewById(R.id.coordinatorlayout);
Snackbar.make(coordinator_layout, "Hi", Snackbar.LENGTH_LONG).show();

Customize snackbar styling

In stylings.xml,

<style name="Widget.Design.Snackbar" parent="android:Widget …

Java verify Error(unchecked exception)

前幾天,在 Google Play Console 收到了二個從使用者回報的 Crash Log,分別是從 Android 5.1 和 4.4 版本所回報的,Android 5.1 的 Traceback:

...
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/adobe/xmp/XMPMetaFactory;
...

Android 4.4 的 Traceback

...
Caused by: java.lang.VerifyError: com/drew/metadata/xmp/XmpReader 
...

我花了一些時間把 tracecode 希望可以找到是那邊發生的,但是一直找不到。最後發現,這邊丟出來的 Error 是 unchecked exceptions 也就是預期是程式有 Bug,所以不會由 Try-catch 來 handle 這種 error。這種 Error 需要丟出來讓外界來把這個 bug 修掉。這個問題是因為我們有用到一個 thirdparty 的 Library 叫 metadata-extractor 其中包含了兩個 jar 檔: metadata-extractor-x.x.x.jarxmpcore-x.x.x.jar。我們因故漏放了xmpcore-x.x.x.jar,導致在處理 xmp 相關的圖檔出現這個錯誤。最後緊急把xmpcore-x.x …

Using Pafers heart rate monitor on a Android 4.3 phone

pafers

For short: You can use PAFERS on BLE Heart Rate Monitor app without any probelm

Find a heart rate monitor on Android

For android phone, it's hard to find a cheap heart rate belt monitor. Some cheap heart rate monitors supprt only ANT+ protocol like Xplova XA-HR2 or PAPAGO! ANT+, you need a GPS running watch to conntect with. For smart phones, we can only use a heart rate monitor that supports bluetooth. However, the most of bluetooth heart rate monitors are using bluetooth 4.0 protocol.

Until versoin 4.3, Android supports bluettoth 4.0 and BLE(bluetooth low …