2016年4月27日 星期三

Android Studio build error: illegal character: '\ufeff'

References:

http://nobodycare.me/2014/11/07/android-studiode-common-questions/
http://www.codegur.net/36027875/character-set-issue-utf-8
http://lifelongprogrammer.blogspot.tw/2014/05/powershell-and-java-stumble-by-utf8-bom.html

Scenario:

Import android project from Eclipse to Android Studio.

Error message:

illegal character: '\ufeff'


Root cause:

The invisible prefix is \ufeff. U+FEFF is byte order mark (BOM).
But java uses utf8 without bom to read file.

Solution:

Opened the document in notepad and changed the encoding to UTF-8 to save it.

2016年4月19日 星期二

Install Android device driver

References:
http://j796160836.pixnet.net/blog/post/29610725

Step:
1. 到 Android SDK Manager裡安裝 Google USB Driver
2. 進入裝置管理員
3. 找到 Android device,右鍵選擇“更新驅動程式”
4. 瀏覽電腦上的驅動程式軟體
5. 讓我從電腦上的裝置驅動程式清單中挑選
6. 從磁碟安裝
7. 選擇  <你裝的android SDK的路徑>\extras\google\usb_driver\android_winusb
例如:
C:\Users\HueiJheYu\AppData\Local\Android\sdk\extras\google\usb_driver\android_winusb
8. Android ADB Interface

2016年4月7日 星期四

Android UriMatcher.addURI中的 /# 和 /* 解释

Reference:
http://bbs.isgphone.com/archiver/tid-6755.html

說明:
* may be used as a wild card for any text, and # may be used as a wild card for numbers
*: 任何字元
#: 任何數字

The difference between getMeasuredHeight() and getHeight()

Reference:
http://blog.csdn.net/xujainxing/article/details/8985063

說明:
getMeasuredHeight() 是 View實際的大小
getHeight() 是 View 在 Screen內的大小
如果 View超出 Screen的邊界時,getMeasuredHeight() = getHeight() + View超出 Screen的大小

2016年3月24日 星期四

Difference between setRepeating and setInexactRepeating of AlarmManager

Reference:

http://stackoverflow.com/questions/21232984/difference-between-setrepeating-and-setinexactrepeating-of-alarmmanager


Example:

alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                AlarmManager.INTERVAL_FIFTEEN_MINUTES, alarmIntent);
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY, alarmIntent);

There are two differences between these calls. The simpler one is that the intent will be sent every fifteen minutes on the first call, and every day on the second call (as you can see in the third parameter). The more complicated difference is the function call itself: setRepeating will schedule the first alarm for exactly every fifteen minutes; setInexactRepeating will schedule the second alarm for approximately every 24 hours, meaning it might deviate from that interval - with the advantage of consuming less power.

Illustration:

setRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)
setInexactRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)

setRepeating在第一次啟動 alarm後,會每隔 intervalMillis啟動一次alarm
setInexactRepeating則是第一次啟動 alarm後,會每隔大約 intervalMillis啟動一次alarm,目的是為了省電,啟動時間相近的 alarm會同時啟動

2016年3月15日 星期二

Get ringtone list from android settings

References:

http://stackoverflow.com/questions/2724871/how-to-bring-up-list-of-available-notification-sounds-on-android

Code snippet:

private static final int RINGTONE_REQUEST_CODE = 5;
public void requestProfileRingtone(){
 
    Intent ringtoneListIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                    ringtoneListIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,     RingtoneManager.TYPE_RINGTONE);
    ringtoneListIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
    ringtoneListIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
    startActivityForResult(ringtoneListIntent, RINGTONE_REQUEST_CODE);
}



@Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent){
        if (resultCode == Activity.RESULT_OK && requestCode == RINGTONE_REQUEST_CODE){
            Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

            if (uri != null){
                Toast.makeText(this, "chosenRingtone: " + uri.toString(), toast.LENGTH_SHORT).show();
                Log.d(TAG, "chosenRingtone: " + uri.toString());
            } else{
                Toast.makeText(this, "chosenRingtone is null", Toast.LENGTH_SHORT).show();
                Log.d(TAG, "chosenRingtone is null");
            }
        }
    }

2016年3月7日 星期一

Send android broadcast by adb

Reference:

http://blog.csdn.net/yelangjueqi/article/details/43231425

Command:

adb shell am broadcast:

[-a <ACTION>]
[-d <DATA_URI>]
[-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[-n <COMPONENT>]
[-f <FLAGS>] [<URI>]

Example:
adb shell am broadcast -a com.android.test --es test_string "this is test string" --ei test_int 100 --ez test_boolean true