2014년 5월 1일 목요일

[Android] Stop Running Task.

Sleep mode 진입 시 구동중인 Application을 정리(중지)
- Sleep / Wake Up 반복시 Task 쌓이는 현상을 피하기 위해 사용.


1. Stop Running Application

    private void stopExecutedApplication() {
        mRunningTaskInfo = mActivityManager.getRunningTasks(Integer.MAX_VALUE);

        for(int i = 0; i < mRunningTaskInfo.size(); i++) {
            int taskId = mRunningTaskInfo.get(i).id;
            String pkgName = mRunningTaskInfo.get(i).baseActivity.getPackageName();
            mActivityManager.removeTask(taskId, ActivityManager.REMOVE_TASK_KILL_PROCESS);
         }
     }


2014년 4월 30일 수요일

[Android] Global Action Dialog

Android 종료 PopUp

Android 기기의 Power key Long Press에 의해 나타나는 Dialog Flow 정리.
- Power Key 를 500ms 이상 누르고 있을 경우, 종료 팝업 D/P


PhoneWindowManager.java ( frameworks/base/policy/src/com/android/internal/policy/impl )
    private final Runnable mPowerLongPress = new Runnable() {
            case LONG_PRESS_POWER_GLOBAL_ACTIONS:
                mPowerKeyHandled = true;
                if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
                    performAuditoryFeedbackForAccessibilityIfNeed();
                }
                sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
                showGlobalActionsDialog();

    private void interceptPowerKeyDown(boolean handled) {
        mPowerKeyHandled = handled;
        if (!handled) {
            mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
        }
    }

ViewConfiguration.java ( frameworks/base/core/java/android/view/ )
    /**
     * Defines the duration in milliseconds a user needs to hold down the
     * appropriate button to bring up the global actions dialog (power off,
     * lock screen, etc).
     */
    private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;

    /**
     * The amount of time a user needs to press the relevant key to bring up
     * the global actions dialog.
     *
     * @return how long a user needs to press the relevant key to bring up
     *   the global actions dialog.
     */
    public static long getGlobalActionKeyTimeout() {
        return GLOBAL_ACTIONS_KEY_TIMEOUT;
    }



2014년 4월 17일 목요일

[Android] Package명으로 Application 실행하기

Package 명으로 Application Start 시키기

Intent intent =
mContext.getPackageManager().getLaunchIntentForPackage(mAppName);

if (intent == null)
    Log.i(TAG,"startActivity Failed. intent is NULL");
else
    mContext.startActivity(intent);



2014년 2월 20일 목요일

[Android] Programmable Bluetooth On/Off.

Android Device의 Bluetooth On/Off 설정 제어하기.


Permissions : 

And add the following permissions into your manifest file:
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

Control On/Off : 

Sample code
public static boolean setBluetooth(boolean enable) {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    boolean isEnabled = bluetoothAdapter.isEnabled();
    if (enable && !isEnabled) {
        return bluetoothAdapter.enable(); 
    }
    else if(!enable && isEnabled) {
        return bluetoothAdapter.disable();
    }
    // No need to change bluetooth state
    return true;
}

But remember these important points:
This is an asynchronous call: it will return immediately, and clients should listen for ACTION_STATE_CHANGED to be notified of subsequent adapter state changes. If this call returns true, then the adapter state will immediately transition from STATE_OFF to STATE_TURNING_ON, and some time later transition to either STATE_OFF or STATE_ON. If this call returns false then there was an immediate problem that will prevent the adapter from being turned on - such as Airplane mode, or the adapter is already turned on.

[Android] Programmable Wi-Fi On/Off

Android Device의 Wi-Fi On/Off 설정 제어하기.


Permissions :

And add the following permissions into your manifest file:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>

Control On/Off.

WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); 
wifiManager.setWifiEnabled(true);
wifiManager.setWifiEnabled(false);

Check Status.

boolean wifiEnabled = wifiManager.isWifiEnabled()


2014년 2월 17일 월요일

Linux Partion Label 확인

Display Linux Partition Label

$ sudo e2label /dev/sda1

Set a new Label

# e2label /dev/sdb2 usbstroage
or
# tune2fs -L usbstroage /dev/sdb2

2014년 2월 15일 토요일

[Android] Adb Shell with RK3066

Rock Chip Device Adb shell 사용하기.

- 참조 : http://linux-rockchip.info/mw/index.php?title=ADB_shell_with_RK3066


Rock Chip device들은 Moborobo 라는 tool을 이용해서 adb 연결을 해야했다.
덕분에 원하지 않더라도 단말에 Moborobo daemon이 설치된다.
개인적으로 이런식의 Apk 설치를 싫어한다.

Windows 와 Linux 환경에서 USB Vendor ID 를 추가를 통해 Android SDK 에 포함된 adb를 이용한 동작을 확인했다.

1. Linux 


1.1 Rock Chip device ( RK3066, RK3188,...) 정보를 Udev rules 파일에 추가.

- Linux 머신과 Device 연결 후 USB Vendor ID 확인. ( RockChip USB Vendor ID는 "2207" 이다.)

$ lsusb
Bus 002 Device 023: ID 2207:0010
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

- Device 정보(USB Vendor ID)를 "/etc/udev/rules.d/51-android.rules" 파일에 추가 후 udev를 restart.
$ sudo vi /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="2207", MODE="0666", GROUP="plugdev"
$ sudo udevadm control --reload-rules

1.2 adb_usb.ini 파일에 RockChip 의 Vendor ID 추가
$ vi ~/.android/adb_usb.ini

# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
0x2207

2. Windows


2.1 Device의 USB Vendor ID를 android_winusb.inf 파일에 추가.
     해당 파일은 Android SDK가 설치된 아래 경로에 존재한다.

path : android\sdk\extras\google\usb_driver\android_winusb.inf
;
; Android WinUsb driver installation.
;


;Google Glass
%SingleAdbInterface%        = USB_Install, USB\VID_18D1&PID_9001
%CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_9001&MI_01


;Rock Chip
%SingleAdbInterface%        = USB_Install, USB\VID_2207&PID_0006&M1_01
%CompositeAdbInterface%     = USB_Install, USB\VID_2207&PID_0006&REV_0222&MI_01


2.2 하드웨어 ID 확인하기.
    - 장치관리자의 속성에서 확인 가능






















2.3 adb_usb.ini 파일에 RockChip 의 Vendor ID 추가


$ vi /cygdrive/c/Users/wschoi/.android/adb_usb.ini

# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
0x2207

2.4 Adb 연결 확인










오늘은 여기까지....