I would like to know exactly what operation a devices home button performs? ie what intent, intent category and action is issued when you click on home button? that takes on back to the blank home screen. I would like to know what is involved in implementing this operation to occur when clicking on my own custom button. Thanks (PS I know it is not standard, but neither is my device).
If you want to show the home screen, you can do it by:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
Update: check this sample app: http://developer.android.com/resources/samples/Home/index.html
This is the intent in xml, in case you are looking for it:
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:excludeFromRecents="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- The following two intent-filters are the key to set homescreen -->
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Please refer here
Also you should be able to see what happens after you click Home button from adb using logcat debug options like;
adb logcat *:W
You can refer to the code:
Button btnHome;
btnHome = (Button) findViewById(R.id.Home);
btnHome.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// sendKey(KeyEvent.KEYCODE_HOME);
myHandler.sendEmptyMessage(Home);
}
});
class myRunnable implements Runnable {
public myRunnable(int key) {
this.keycode = key;
}
int keycode;
@Override
public void run() {
sendKey(keycode);
}
public void sendKey(int keyCode) {
System.out.println("Judy--------------------->sendkey " + keyCode);
long now = SystemClock.uptimeMillis();
long n = System.currentTimeMillis();
try {
KeyEvent down = new KeyEvent(now, now, KeyEvent.ACTION_DOWN,
keyCode, 0);
KeyEvent up = new KeyEvent(now, now, KeyEvent.ACTION_UP,keyCode, 0);
IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager
.getService("window"));
wm.injectKeyEvent(down, false);
wm.injectKeyEvent(up, false);
} catch (RemoteException e) {}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.