2014년 7월 27일 일요일

[Android] Stop Audio Player

Stop Audio Player 


        Intent intent = new Intent("com.android.music.musicservicecommand");
        intent.putExtra("command", "pause");

        mContext.sendBroadcast(intent);


MediaPlaybackService commands


 public class MediaPlaybackService extends Service {

     public static final String PLAYSTATE_CHANGED = "com.android.music.playstatechanged";
     public static final String META_CHANGED = "com.android.music.metachanged";
     public static final String QUEUE_CHANGED = "com.android.music.queuechanged";

     public static final String SERVICECMD = "com.android.music.musicservicecommand";
     public static final String CMDNAME = "command";
     public static final String CMDTOGGLEPAUSE = "togglepause";
     public static final String CMDSTOP = "stop";
     public static final String CMDPAUSE = "pause";
     public static final String CMDPLAY = "play";
     public static final String CMDPREVIOUS = "previous";
     public static final String CMDNEXT = "next";
     public static final String TOGGLEPAUSE_ACTION = "com.android.music.musicservicecommand.togglepause";
     public static final String PAUSE_ACTION = "com.android.music.musicservicecommand.pause";
     public static final String PREVIOUS_ACTION = "com.android.music.musicservicecommand.previous";
     public static final String NEXT_ACTION = "com.android.music.musicservicecommand.next";

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