WEB开发网
开发学院手机开发Android 开发 在android的状态栏(statusbar)中增加menu,home和... 阅读

在android的状态栏(statusbar)中增加menu,home和back快捷键的方法

 2010-09-15 00:01:00 来源:WEB开发网   
核心提示:break;case R.id.status_vol_down:mKeysHandler.sendEmptyMessage(KEY_VOL_DOWN);break;default:break;}}};4.添加模拟按键处理/* Begin : ADDED by TigerPan 20100831 */private st

break;

case R.id.status_vol_down:

mKeysHandler.sendEmptyMessage(KEY_VOL_DOWN);

break;

default:

break;

}

}};

4.添加模拟按键处理

/* Begin : ADDED by TigerPan 20100831 */

private static final int KEY_HOME = 1000;

private static final int KEY_BACK = 1001;

private static final int KEY_MENU = 1002;

private static final int KEY_VOL_UP = 1003;

private static final int KEY_VOL_DOWN = 1004;

private Handler mKeysHandler = new Handler(){

public void handleMessage(Message msg) {

switch (msg.what) {

case KEY_HOME:

sendKey(KeyEvent.KEYCODE_HOME);

break;

case KEY_BACK:

sendKey(KeyEvent.KEYCODE_BACK);

break;

case KEY_MENU:

sendKey(KeyEvent.KEYCODE_MENU);

break;

case KEY_VOL_UP:

((android.media.AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE))

.adjustVolume(android.media.AudioManager.ADJUST_RAISE, android.media.AudioManager.STREAM_MUSIC);

break;

case KEY_VOL_DOWN:

((android.media.AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE))

.adjustVolume(android.media.AudioManager.ADJUST_LOWER, android.media.AudioManager.STREAM_MUSIC);

break;

default:

break;

}

}

private void sendKey(int keyCode) {

long now = SystemClock.uptimeMillis();

long n = System.currentTimeMillis();

Log.d("Tiger", "Intent.ACTION_SOFT_"+keyCode+"_PRESSED 0="+n);

try {

KeyEvent down = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyCode, 0);

KeyEvent up = new KeyEvent(now, now, KeyEvent.ACTION_UP, keyCode, 0);

Log.d("Tiger", "Intent.ACTION_SOFT_"+keyCode+"_PRESSED

上一页  1 2 3 4 5 6  下一页

Tags:android 状态 statusbar

编辑录入:coldstar [复制链接] [打 印]
赞助商链接