I have developed and app that use camera hardware on Samsung Galaxy J7 to measure light and adjust display brightness when home screen was pressed. But I got problem that when home screen was double pressed, as I set short cut for opening build-in camera app. The camera got black screen (camera hardware not work). I would like to make my app to be able to detect home screen double pressed so that it can skip using camera hardware and let build-in camera app work properly.
PS. Do not advise me to use 'long press' or 'recent app key' , because I have already used them. ^^
With code would be good. Thank you in advance.
This is option 1 code base on @saeed suggestion: it work but not absolutely perfect.
if(firstHomePressed == true){
firstHomePressed = false;
secondHomePressed = false;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(secondHomePressed == false){
Toast.makeText(mContext,"Pressed Once",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(mContext, "Double Pressed", Toast.LENGTH_SHORT).show();
}
firstHomePressed = true;
}
}, 1000);
}
else{
secondHomePressed = true;
Toast.makeText(mContext, "secondHomePressed : true", Toast.LENGTH_SHORT).show();
}
I figure out that by using "Intent.ACTION_CLOSE_SYSTEM_DIALOGS" to detect home key press action as I use, double home button presses will invoke the receiver only one time (even double press on home button).
if (intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
{
String reason = intent.getStringExtra(SYSTEM_REASON);
//Toast.makeText(context,"ACTION_CLOSE_SYSTEM_DIALOGS : Reason : " + reason ,Toast.LENGTH_LONG).show();
// Detect home screen key press or "recent app" key pressed when screen is in unlocked state
if (reason != null)
{
MainActivity.logForDebug("MyThread", "reason : " + reason);
if (reason.equals(SYSTEM_HOME_KEY)) {
}
}
}
Anyway I got the solution. I put more delay before my app start when single or double home button pressed, to let default camera app start before my app. Then default camera can work finely.
However still do not know how to detect double pressed on home button correctly. ^^